feat: add article and production modules

This commit is contained in:
2026-08-31 13:16:46 +08:00
parent ac3da246b2
commit 5c586a1a95
334 changed files with 34419 additions and 1 deletions
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use core\tool\Json;
use madong\swagger\annotation\response\DataResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ExceptionAnalysisService;
use support\annotation\Middleware;
use support\Request;
use support\Response;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ExceptionAnalysisController
{
public function __construct(protected ExceptionAnalysisService $service)
{
}
#[OA\Get(path: '/produce/exception-analysis/overview', summary: '异常数据分析', tags: ['produce-exception-analysis'])]
#[DataResponse(description: '获取异常数据分析成功')]
#[Permission(code: 'produce:exception-analysis:read', description: '查看异常数据分析')]
public function overview(Request $request): Response
{
return Json::success('获取成功', $this->service->overview($request->all()));
}
}
@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ExceptionRecordService;
use plugin\produce\app\validate\ExceptionRecordValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ExceptionRecordController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['order_no', 'user_code', 'reporter', 'type_name', 'reason_name', 'issue_name', 'remark'],
];
public function __construct(ExceptionRecordService $service, ExceptionRecordValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/exception-record', summary: '异常数据列表', tags: ['produce-exception-record'])]
#[Permission(code: 'produce:exception-data:list', description: '异常数据列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(path: '/produce/exception-record/{id}', summary: '异常数据详情', tags: ['produce-exception-record'], x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
])]
#[Permission(code: 'produce:exception-data:read', description: '异常数据详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/exception-record', summary: '创建异常数据', tags: ['produce-exception-record'])]
#[Permission(code: 'produce:exception-data:create', description: '创建异常数据')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(path: '/produce/exception-record/{id}', summary: '更新异常数据', tags: ['produce-exception-record'], x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
])]
#[Permission(code: 'produce:exception-data:update', description: '更新异常数据')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/exception-record/export', summary: '导出异常数据', tags: ['produce-exception-record'])]
#[Permission(code: 'produce:exception-data:list', description: '导出异常数据')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(path: '/produce/exception-record/{id}', summary: '删除异常数据', tags: ['produce-exception-record'], x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
])]
#[Permission(code: 'produce:exception-data:delete', description: '删除异常数据')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(path: '/produce/exception-record', summary: '批量删除异常数据', tags: ['produce-exception-record'], x: [
SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class,
])]
#[Permission(code: 'produce:exception-data:delete', description: '批量删除异常数据')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ExceptionSettingService;
use plugin\produce\app\validate\ExceptionSettingValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ExceptionSettingController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['code', 'name', 'remark'],
];
public function __construct(ExceptionSettingService $service, ExceptionSettingValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/exception-setting', summary: '异常设置列表', tags: ['produce-exception-setting'])]
#[Permission(code: 'produce:exception-setting:list', description: '异常设置列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(path: '/produce/exception-setting/{id}', summary: '异常设置详情', tags: ['produce-exception-setting'], x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
])]
#[Permission(code: 'produce:exception-setting:read', description: '异常设置详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/exception-setting', summary: '创建异常设置', tags: ['produce-exception-setting'])]
#[Permission(code: 'produce:exception-setting:create', description: '创建异常设置')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(path: '/produce/exception-setting/{id}', summary: '更新异常设置', tags: ['produce-exception-setting'], x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
])]
#[Permission(code: 'produce:exception-setting:update', description: '更新异常设置')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Delete(path: '/produce/exception-setting/{id}', summary: '删除异常设置', tags: ['produce-exception-setting'], x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
])]
#[Permission(code: 'produce:exception-setting:delete', description: '删除异常设置')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(path: '/produce/exception-setting', summary: '批量删除异常设置', tags: ['produce-exception-setting'], x: [
SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class,
])]
#[Permission(code: 'produce:exception-setting:delete', description: '批量删除异常设置')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use core\tool\Json;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\HardwareFaultDescriptionService;
use plugin\produce\app\validate\HardwareFaultDescriptionValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class HardwareFaultDescriptionController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['description', 'remark'],
];
public function __construct(HardwareFaultDescriptionService $service, HardwareFaultDescriptionValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/hardware-fault-description', summary: '硬件故障描述列表', tags: ['produce-hardware-fault-description'])]
#[Permission(code: 'produce:hardware-fault-description:list', description: '硬件故障描述列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response { return parent::index($request); }
#[OA\Post(path: '/produce/hardware-fault-description/import', summary: '导入硬件故障描述', tags: ['produce-hardware-fault-description'])]
#[Permission(code: 'produce:hardware-fault-description:import', description: '导入硬件故障描述')]
#[SimpleResponse(schema: [], example: [])]
public function import(Request $request): \support\Response
{
try {
$file = $request->file('file');
if (!$file) {
return Json::fail('请选择Excel文件');
}
if ($file->getSize() > 5 * 1024 * 1024) {
return Json::fail('Excel文件不能超过5MB');
}
$extension = strtolower((string) $file->getUploadExtension());
if (!in_array($extension, ['xlsx', 'xls', 'csv'], true)) {
return Json::fail('只支持xlsx、xls或csv格式文件');
}
$result = $this->service->importFromExcel($file->getPathname());
return Json::success('导入成功', $result);
} catch (\Throwable $e) {
return Json::fail($e->getMessage());
}
}
#[OA\Get(path: '/produce/hardware-fault-description/{id}', summary: '硬件故障描述详情', tags: ['produce-hardware-fault-description'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:hardware-fault-description:read', description: '硬件故障描述详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response { return parent::show($request); }
#[OA\Post(path: '/produce/hardware-fault-description', summary: '创建硬件故障描述', tags: ['produce-hardware-fault-description'])]
#[Permission(code: 'produce:hardware-fault-description:create', description: '创建硬件故障描述')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response { return parent::store($request); }
#[OA\Put(path: '/produce/hardware-fault-description/{id}', summary: '更新硬件故障描述', tags: ['produce-hardware-fault-description'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:hardware-fault-description:update', description: '更新硬件故障描述')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response { return parent::update($request); }
#[OA\Delete(path: '/produce/hardware-fault-description/{id}', summary: '删除硬件故障描述', tags: ['produce-hardware-fault-description'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:hardware-fault-description:delete', description: '删除硬件故障描述')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response { return parent::destroy($request); }
#[OA\Delete(path: '/produce/hardware-fault-description', summary: '批量删除硬件故障描述', tags: ['produce-hardware-fault-description'], x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class])]
#[Permission(code: 'produce:hardware-fault-description:delete', description: '批量删除硬件故障描述')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response { return parent::destroy($request); }
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\MaterialCategoryService;
use plugin\produce\app\validate\MaterialCategoryValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class MaterialCategoryController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['category_name'],
];
public function __construct(MaterialCategoryService $service, MaterialCategoryValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/material-category', summary: '物料分类列表', tags: ['produce-material-category'])]
#[Permission(code: 'produce:material-category:list', description: '物料分类列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response { return parent::index($request); }
#[OA\Get(path: '/produce/material-category/{id}', summary: '物料分类详情', tags: ['produce-material-category'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:material-category:read', description: '物料分类详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response { return parent::show($request); }
#[OA\Post(path: '/produce/material-category', summary: '创建物料分类', tags: ['produce-material-category'])]
#[Permission(code: 'produce:material-category:create', description: '创建物料分类')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response { return parent::store($request); }
#[OA\Put(path: '/produce/material-category/{id}', summary: '更新物料分类', tags: ['produce-material-category'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:material-category:update', description: '更新物料分类')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response { return parent::update($request); }
#[OA\Delete(path: '/produce/material-category/{id}', summary: '删除物料分类', tags: ['produce-material-category'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:material-category:delete', description: '删除物料分类')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response { return parent::destroy($request); }
#[OA\Delete(path: '/produce/material-category', summary: '批量删除物料分类', tags: ['produce-material-category'], x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class])]
#[Permission(code: 'produce:material-category:delete', description: '批量删除物料分类')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response { return parent::destroy($request); }
}
@@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use core\tool\Json;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\MaterialService;
use plugin\produce\app\validate\MaterialValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class MaterialController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['product_code', 'product_name'],
];
public function __construct(MaterialService $service, MaterialValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/material', summary: '物料列表', tags: ['produce-material'])]
#[Permission(code: 'produce:material:list', description: '物料列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response { return parent::index($request); }
#[OA\Post(path: '/produce/material/import', summary: '导入物料', tags: ['produce-material'])]
#[Permission(code: 'produce:material:import', description: '导入物料')]
#[SimpleResponse(schema: [], example: [])]
public function import(Request $request): \support\Response
{
try {
$file = $request->file('file');
if (!$file) {
return Json::fail('请选择Excel文件');
}
if ($file->getSize() > 5 * 1024 * 1024) {
return Json::fail('Excel文件不能超过5MB');
}
$extension = strtolower((string) $file->getUploadExtension());
if (!in_array($extension, ['xlsx', 'xls', 'csv'], true)) {
return Json::fail('只支持xlsx、xls或csv格式文件');
}
$result = $this->service->importFromExcel($file->getPathname());
return Json::success('导入成功', $result);
} catch (\Throwable $e) {
return Json::fail($e->getMessage());
}
}
#[OA\Get(path: '/produce/material/{id}', summary: '物料详情', tags: ['produce-material'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:material:read', description: '物料详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response { return parent::show($request); }
#[OA\Post(path: '/produce/material', summary: '创建物料', tags: ['produce-material'])]
#[Permission(code: 'produce:material:create', description: '创建物料')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response { return parent::store($request); }
#[OA\Put(path: '/produce/material/{id}', summary: '更新物料', tags: ['produce-material'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:material:update', description: '更新物料')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response { return parent::update($request); }
#[OA\Post(path: '/produce/material/export', summary: '导出物料', tags: ['produce-material'])]
#[Permission(code: 'produce:material:list', description: '导出物料')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response { return parent::export($request); }
#[OA\Delete(path: '/produce/material/{id}', summary: '删除物料', tags: ['produce-material'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:material:delete', description: '删除物料')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response { return parent::destroy($request); }
#[OA\Delete(path: '/produce/material', summary: '批量删除物料', tags: ['produce-material'], x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class])]
#[Permission(code: 'produce:material:delete', description: '批量删除物料')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response { return parent::destroy($request); }
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ProcessService;
use plugin\produce\app\validate\ProcessValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ProcessController extends Crud
{
public function __construct(ProcessService $service, ProcessValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/process', summary: '工序管理列表', tags: ['produce-process'])]
#[Permission(code: 'produce:process:list', description: '工序管理列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/process/{id}',
summary: '工序管理详情',
tags: ['produce-process'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:process:read', description: '工序管理详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/process', summary: '创建工序', tags: ['produce-process'])]
#[Permission(code: 'produce:process:create', description: '创建工序')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/process/{id}',
summary: '更新工序',
tags: ['produce-process'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:process:update', description: '更新工序')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/process/export', summary: '导出工序', tags: ['produce-process'])]
#[Permission(code: 'produce:process:list', description: '导出工序')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/process/{id}',
summary: '删除工序',
tags: ['produce-process'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:process:delete', description: '删除工序')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/process',
summary: '批量删除工序',
tags: ['produce-process'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:process:delete', description: '批量删除工序')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ProcessStepService;
use plugin\produce\app\validate\ProcessStepValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ProcessStepController extends Crud
{
public function __construct(ProcessStepService $service, ProcessStepValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/process-step', summary: '工序步骤列表', tags: ['produce-process-step'])]
#[Permission(code: 'produce:process-step:list', description: '工序步骤列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/process-step/{id}',
summary: '工序步骤详情',
tags: ['produce-process-step'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:process-step:read', description: '工序步骤详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/process-step', summary: '创建工序步骤', tags: ['produce-process-step'])]
#[Permission(code: 'produce:process-step:create', description: '创建工序步骤')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/process-step/{id}',
summary: '更新工序步骤',
tags: ['produce-process-step'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:process-step:update', description: '更新工序步骤')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/process-step/export', summary: '导出工序步骤', tags: ['produce-process-step'])]
#[Permission(code: 'produce:process-step:list', description: '导出工序步骤')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/process-step/{id}',
summary: '删除工序步骤',
tags: ['produce-process-step'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:process-step:delete', description: '删除工序步骤')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/process-step',
summary: '批量删除工序步骤',
tags: ['produce-process-step'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:process-step:delete', description: '批量删除工序步骤')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use core\tool\Json;
use madong\swagger\annotation\response\DataResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ProduceConfigService;
use support\annotation\Middleware;
use support\Request;
use support\Response;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ProduceConfigController
{
public function __construct(protected ProduceConfigService $service)
{
}
#[OA\Get(path: '/produce/config/info', summary: '获取生产配置', tags: ['produce-config'])]
#[DataResponse(description: '获取成功')]
#[Permission(code: 'produce:config:read', description: '查看生产配置')]
public function info(Request $request): Response
{
$groupCode = (string) $request->input('group_code', '');
if ($groupCode === '') {
return Json::fail('配置组代码不能为空');
}
return Json::success('获取成功', $this->service->getConfigByGroup($groupCode));
}
#[OA\Post(path: '/produce/config/save', summary: '保存生产配置', tags: ['produce-config'])]
#[SimpleResponse(description: '保存成功')]
#[Permission(code: 'produce:config:update', description: '保存生产配置')]
public function save(Request $request): Response
{
$payload = $request->post();
$groupCode = (string) ($payload['group_code'] ?? '');
$configs = $payload['configs'] ?? [];
if ($groupCode === '') {
return Json::fail('配置组代码不能为空');
}
if (!is_array($configs) || $configs === []) {
return Json::fail('配置数据不能为空');
}
$this->service->saveConfig($groupCode, $configs);
return Json::success('保存成功');
}
}
@@ -0,0 +1,82 @@
<?php
/**
* Produce 控制器
*/
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use core\tool\Json;
use madong\swagger\annotation\response\DataResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use madong\swagger\attribute\AllowAnonymous;
use OpenApi\Attributes as OA;
use support\annotation\Middleware;
use support\Request;
use support\Response;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ProduceController
{
#[OA\Get(
path: '/produce/index',
summary: '获取列表',
tags: ['produce']
)]
#[DataResponse(description: '获取成功')]
#[Permission(code: 'produce:index', description: '列表权限')]
public function index(Request $request): Response
{
return Json::success('获取成功', []);
}
#[OA\Post(
path: '/produce/create',
summary: '创建',
tags: ['produce']
)]
#[SimpleResponse(description: '创建成功')]
#[Permission(code: 'produce:create', description: '创建权限')]
public function create(Request $request): Response
{
return Json::success('创建成功');
}
#[OA\Get(
path: '/produce/info',
summary: '详情',
tags: ['produce']
)]
#[DataResponse(description: '获取成功')]
#[Permission(code: 'produce:info', description: '详情权限')]
public function info(Request $request): Response
{
return Json::success('获取成功', []);
}
#[OA\Post(
path: '/produce/update',
summary: '更新',
tags: ['produce']
)]
#[SimpleResponse(description: '更新成功')]
#[Permission(code: 'produce:update', description: '更新权限')]
public function update(Request $request): Response
{
return Json::success('更新成功');
}
#[OA\Post(
path: '/produce/delete',
summary: '删除',
tags: ['produce']
)]
#[SimpleResponse(description: '删除成功')]
#[Permission(code: 'produce:delete', description: '删除权限')]
public function delete(Request $request): Response
{
return Json::success('删除成功');
}
}
@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ProductRecordService;
use plugin\produce\app\validate\ProductRecordValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ProductRecordController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['process_order_no', 'product_code', 'operator', 'remark'],
];
public function __construct(ProductRecordService $service, ProductRecordValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/product-record', summary: '整机数据列表', tags: ['produce-product-record'])]
#[Permission(code: 'produce:product-record:list', description: '整机数据列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/product-record/{id}',
summary: '整机数据详情',
tags: ['produce-product-record'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:product-record:read', description: '整机数据详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/product-record', summary: '创建整机数据', tags: ['produce-product-record'])]
#[Permission(code: 'produce:product-record:create', description: '创建整机数据')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/product-record/{id}',
summary: '更新整机数据',
tags: ['produce-product-record'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:product-record:update', description: '更新整机数据')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/product-record/export', summary: '导出整机数据', tags: ['produce-product-record'])]
#[Permission(code: 'produce:product-record:list', description: '导出整机数据')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/product-record/{id}',
summary: '删除整机数据',
tags: ['produce-product-record'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:product-record:delete', description: '删除整机数据')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/product-record',
summary: '批量删除整机数据',
tags: ['produce-product-record'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:product-record:delete', description: '批量删除整机数据')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use core\tool\Json;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\RepairRecordService;
use plugin\produce\app\validate\RepairRecordValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class RepairRecordController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['repair_no', 'order_no', 'product_code', 'product_name', 'fault_description', 'operator', 'remark'],
];
public function __construct(RepairRecordService $service, RepairRecordValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/repair-record', summary: '维修数据列表', tags: ['produce-repair-record'])]
#[Permission(code: 'produce:repair-record:list', description: '维修数据列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
try {
[$where, $format, $limit, $field, $order, $page] = $this->selectInput($request);
$methods = [
'select' => 'formatSelect',
'tree' => 'formatTree',
'table_tree' => 'formatTableTree',
'normal' => 'formatNormal',
];
$order = $order ?: 'repaired_at DESC, id DESC';
$total = $this->service->getCount($where);
$list = $this->service->selectList($where, $field, $page, $limit, $order, [], false);
return call_user_func([$this, $methods[$format] ?? 'formatNormal'], $list, $total);
} catch (\Throwable $e) {
return Json::fail($e->getMessage());
}
}
#[OA\Get(path: '/produce/repair-record/{id}', summary: '维修数据详情', tags: ['produce-repair-record'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:repair-record:read', description: '维修数据详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response { return parent::show($request); }
#[OA\Post(path: '/produce/repair-record', summary: '创建维修数据', tags: ['produce-repair-record'])]
#[Permission(code: 'produce:repair-record:create', description: '创建维修数据')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response { return parent::store($request); }
#[OA\Put(path: '/produce/repair-record/{id}', summary: '更新维修数据', tags: ['produce-repair-record'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:repair-record:update', description: '更新维修数据')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response { return parent::update($request); }
protected function expandExportRows(iterable $items): iterable
{
foreach ($items as $item) {
$record = $item->toArray();
$parts = is_array($record['parts'] ?? null) ? $record['parts'] : [];
if (!$parts) {
yield $record;
continue;
}
foreach ($parts as $part) {
$faultDescriptions = is_array($part['fault_descriptions'] ?? null) ? $part['fault_descriptions'] : [];
$record['order_product'] = implode('/', array_filter([(string) ($record['order_no'] ?? ''), (string) ($record['product_code'] ?? '')]));
$record['part_category'] = (string) ($part['category_name'] ?? '-');
$record['part_code'] = (string) ($part['product_code'] ?? '-');
$record['part_name'] = (string) ($part['product_name'] ?? '-');
$record['part_fault'] = implode('、', array_filter(array_map(
static fn (array $fault): string => (string) ($fault['description'] ?? ''),
$faultDescriptions,
))) ?: '-';
$record['part_quantity'] = (string) ($part['quantity'] ?? 1);
$record['part_source'] = match ($part['source'] ?? '') {
'new' => '新料',
'old', 'after_sale', 'after_sales', 'after-sale' => '售后',
'repair', 'refurbished' => '返修',
default => (string) ($part['source'] ?? '-'),
};
yield $record;
}
}
}
#[OA\Post(path: '/produce/repair-record/export', summary: '导出维修数据', tags: ['produce-repair-record'])]
#[Permission(code: 'produce:repair-record:list', description: '导出维修数据')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(path: '/produce/repair-record/{id}', summary: '删除维修数据', tags: ['produce-repair-record'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:repair-record:delete', description: '删除维修数据')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
try {
$ids = $this->getDeleteIds($request);
if (!$ids) {
return Json::fail('删除参数不能为空');
}
$this->service->transaction(function () use ($ids) {
foreach ($ids as $id) {
$this->service->deleteRecord($id);
}
});
return Json::success('ok', $ids);
} catch (\Throwable $e) {
return Json::fail($e->getMessage());
}
}
#[OA\Delete(path: '/produce/repair-record', summary: '批量删除维修数据', tags: ['produce-repair-record'], x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class])]
#[Permission(code: 'produce:repair-record:delete', description: '批量删除维修数据')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response { return $this->destroy($request); }
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\RepairSettingService;
use plugin\produce\app\validate\RepairSettingValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class RepairSettingController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['code', 'name', 'remark'],
];
public function __construct(RepairSettingService $service, RepairSettingValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/repair-setting', summary: '维修设置列表', tags: ['produce-repair-setting'])]
#[Permission(code: 'produce:repair-setting:list', description: '维修设置列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response { return parent::index($request); }
#[OA\Get(path: '/produce/repair-setting/{id}', summary: '维修设置详情', tags: ['produce-repair-setting'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:repair-setting:read', description: '维修设置详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response { return parent::show($request); }
#[OA\Post(path: '/produce/repair-setting', summary: '创建维修设置', tags: ['produce-repair-setting'])]
#[Permission(code: 'produce:repair-setting:create', description: '创建维修设置')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response { return parent::store($request); }
#[OA\Put(path: '/produce/repair-setting/{id}', summary: '更新维修设置', tags: ['produce-repair-setting'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:repair-setting:update', description: '更新维修设置')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response { return parent::update($request); }
#[OA\Delete(path: '/produce/repair-setting/{id}', summary: '删除维修设置', tags: ['produce-repair-setting'], x: [SchemaConstants::X_PROPERTY_IN => 'id', SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class])]
#[Permission(code: 'produce:repair-setting:delete', description: '删除维修设置')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response { return parent::destroy($request); }
#[OA\Delete(path: '/produce/repair-setting', summary: '批量删除维修设置', tags: ['produce-repair-setting'], x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class])]
#[Permission(code: 'produce:repair-setting:delete', description: '批量删除维修设置')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response { return parent::destroy($request); }
}
@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\ScanDataService;
use plugin\produce\app\validate\ScanDataValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class ScanDataController extends Crud
{
protected ?array $selectInputConfig = [
'enable_keyword_search' => true,
'keyword_fields' => ['order_no', 'user_code', 'operator', 'remark'],
];
public function __construct(ScanDataService $service, ScanDataValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/scan-data', summary: '扫码数据列表', tags: ['produce-scan-data'])]
#[Permission(code: 'produce:scan-data:list', description: '扫码数据列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/scan-data/{id}',
summary: '扫码数据详情',
tags: ['produce-scan-data'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:scan-data:read', description: '扫码数据详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/scan-data', summary: '创建扫码数据', tags: ['produce-scan-data'])]
#[Permission(code: 'produce:scan-data:create', description: '创建扫码数据')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/scan-data/{id}',
summary: '更新扫码数据',
tags: ['produce-scan-data'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:scan-data:update', description: '更新扫码数据')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/scan-data/export', summary: '导出扫码数据', tags: ['produce-scan-data'])]
#[Permission(code: 'produce:scan-data:list', description: '导出扫码数据')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/scan-data/{id}',
summary: '删除扫码数据',
tags: ['produce-scan-data'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:scan-data:delete', description: '删除扫码数据')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/scan-data',
summary: '批量删除扫码数据',
tags: ['produce-scan-data'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:scan-data:delete', description: '批量删除扫码数据')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\SpecificRuleService;
use plugin\produce\app\validate\SpecificRuleValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class SpecificRuleController extends Crud
{
public function __construct(SpecificRuleService $service, SpecificRuleValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/specific-rule', summary: '特定规则列表', tags: ['produce-specific-rule'])]
#[Permission(code: 'produce:specific-rule:list', description: '特定规则列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/specific-rule/{id}',
summary: '特定规则详情',
tags: ['produce-specific-rule'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:specific-rule:read', description: '特定规则详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/specific-rule', summary: '创建特定规则', tags: ['produce-specific-rule'])]
#[Permission(code: 'produce:specific-rule:create', description: '创建特定规则')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/specific-rule/{id}',
summary: '更新特定规则',
tags: ['produce-specific-rule'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:specific-rule:update', description: '更新特定规则')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/specific-rule/export', summary: '导出特定规则', tags: ['produce-specific-rule'])]
#[Permission(code: 'produce:specific-rule:list', description: '导出特定规则')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/specific-rule/{id}',
summary: '删除特定规则',
tags: ['produce-specific-rule'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:specific-rule:delete', description: '删除特定规则')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/specific-rule',
summary: '批量删除特定规则',
tags: ['produce-specific-rule'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:specific-rule:delete', description: '批量删除特定规则')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\StatusTransitionService;
use plugin\produce\app\validate\StatusTransitionValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class StatusTransitionController extends Crud
{
public function __construct(StatusTransitionService $service, StatusTransitionValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/status-transition', summary: '状态转换规则列表', tags: ['produce-status-transition'])]
#[Permission(code: 'produce:status-transition:list', description: '状态转换规则列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/status-transition/{id}',
summary: '状态转换规则详情',
tags: ['produce-status-transition'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:status-transition:read', description: '状态转换规则详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/status-transition', summary: '创建状态转换规则', tags: ['produce-status-transition'])]
#[Permission(code: 'produce:status-transition:create', description: '创建状态转换规则')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/status-transition/{id}',
summary: '更新状态转换规则',
tags: ['produce-status-transition'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:status-transition:update', description: '更新状态转换规则')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/status-transition/export', summary: '导出状态转换规则', tags: ['produce-status-transition'])]
#[Permission(code: 'produce:status-transition:list', description: '导出状态转换规则')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/status-transition/{id}',
summary: '删除状态转换规则',
tags: ['produce-status-transition'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:status-transition:delete', description: '删除状态转换规则')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/status-transition',
summary: '批量删除状态转换规则',
tags: ['produce-status-transition'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:status-transition:delete', description: '批量删除状态转换规则')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\StepRelationService;
use plugin\produce\app\validate\StepRelationValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class StepRelationController extends Crud
{
public function __construct(StepRelationService $service, StepRelationValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/step-relation', summary: '步骤关系列表', tags: ['produce-step-relation'])]
#[Permission(code: 'produce:step-relation:list', description: '步骤关系列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/step-relation/{id}',
summary: '步骤关系详情',
tags: ['produce-step-relation'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:step-relation:read', description: '步骤关系详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/step-relation', summary: '创建步骤关系', tags: ['produce-step-relation'])]
#[Permission(code: 'produce:step-relation:create', description: '创建步骤关系')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/step-relation/{id}',
summary: '更新步骤关系',
tags: ['produce-step-relation'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:step-relation:update', description: '更新步骤关系')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/step-relation/export', summary: '导出步骤关系', tags: ['produce-step-relation'])]
#[Permission(code: 'produce:step-relation:list', description: '导出步骤关系')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/step-relation/{id}',
summary: '删除步骤关系',
tags: ['produce-step-relation'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:step-relation:delete', description: '删除步骤关系')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/step-relation',
summary: '批量删除步骤关系',
tags: ['produce-step-relation'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:step-relation:delete', description: '批量删除步骤关系')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\BatchDeleteRequest;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\StepStatusService;
use plugin\produce\app\validate\StepStatusValidate;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class StepStatusController extends Crud
{
public function __construct(StepStatusService $service, StepStatusValidate $validate)
{
$this->service = $service;
$this->validate = $validate;
}
#[OA\Get(path: '/produce/step-status', summary: '步骤状态列表', tags: ['produce-step-status'])]
#[Permission(code: 'produce:step-status:list', description: '步骤状态列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/step-status/{id}',
summary: '步骤状态详情',
tags: ['produce-step-status'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:step-status:read', description: '步骤状态详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/step-status', summary: '创建步骤状态', tags: ['produce-step-status'])]
#[Permission(code: 'produce:step-status:create', description: '创建步骤状态')]
#[SimpleResponse(schema: [], example: [])]
public function store(Request $request): \support\Response
{
return parent::store($request);
}
#[OA\Put(
path: '/produce/step-status/{id}',
summary: '更新步骤状态',
tags: ['produce-step-status'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:step-status:update', description: '更新步骤状态')]
#[SimpleResponse(schema: [], example: [])]
public function update(Request $request): \support\Response
{
return parent::update($request);
}
#[OA\Post(path: '/produce/step-status/export', summary: '导出步骤状态', tags: ['produce-step-status'])]
#[Permission(code: 'produce:step-status:list', description: '导出步骤状态')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
#[OA\Delete(
path: '/produce/step-status/{id}',
summary: '删除步骤状态',
tags: ['produce-step-status'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:step-status:delete', description: '删除步骤状态')]
#[SimpleResponse(schema: [], example: [])]
public function destroy(Request $request): \support\Response
{
return parent::destroy($request);
}
#[OA\Delete(
path: '/produce/step-status',
summary: '批量删除步骤状态',
tags: ['produce-step-status'],
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
)]
#[Permission(code: 'produce:step-status:delete', description: '批量删除步骤状态')]
#[SimpleResponse(schema: [], example: [])]
public function batchDelete(Request $request): \support\Response
{
return parent::destroy($request);
}
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\controller\Crud;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use app\schema\request\IdRequest;
use madong\swagger\annotation\response\PageResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\TransitionLogService;
use support\annotation\Middleware;
use support\Request;
use WebmanTech\Swagger\DTO\SchemaConstants;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class TransitionLogController extends Crud
{
public function __construct(TransitionLogService $service)
{
$this->service = $service;
}
#[OA\Get(path: '/produce/transition-log', summary: '转换日志列表', tags: ['produce-transition-log'])]
#[Permission(code: 'produce:transition-log:list', description: '转换日志列表')]
#[PageResponse(schema: [], example: [])]
public function index(Request $request): \support\Response
{
return parent::index($request);
}
#[OA\Get(
path: '/produce/transition-log/{id}',
summary: '转换日志详情',
tags: ['produce-transition-log'],
x: [
SchemaConstants::X_PROPERTY_IN => 'id',
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
]
)]
#[Permission(code: 'produce:transition-log:read', description: '转换日志详情')]
#[SimpleResponse(schema: [], example: [])]
public function show(Request $request): \support\Response
{
return parent::show($request);
}
#[OA\Post(path: '/produce/transition-log/export', summary: '导出转换日志', tags: ['produce-transition-log'])]
#[Permission(code: 'produce:transition-log:list', description: '导出转换日志')]
#[SimpleResponse(schema: [], example: [])]
public function export(Request $request): \support\Response
{
return parent::export($request);
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\adminapi\controller;
use app\adminapi\middleware\OperationMiddleware;
use app\adminapi\middleware\PermissionMiddleware;
use core\tool\Json;
use madong\swagger\annotation\response\DataResponse;
use madong\swagger\attribute\Permission;
use OpenApi\Attributes as OA;
use plugin\produce\app\service\admin\WorkStatisticsService;
use support\annotation\Middleware;
use support\Request;
use support\Response;
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
class WorkStatisticsController
{
public function __construct(protected WorkStatisticsService $service)
{
}
#[OA\Get(path: '/produce/statistics/monthly', summary: '月工作统计', tags: ['produce-statistics'])]
#[DataResponse(description: '获取月工作统计成功')]
#[Permission(code: 'produce:statistics:monthly', description: '月工作统计')]
public function monthly(Request $request): Response
{
return Json::success('获取成功', [
'columns' => $this->monthlyColumns((string) $request->input('month', date('Y-m'))),
'items' => $this->service->monthly($request->all()),
]);
}
#[OA\Get(path: '/produce/statistics/daily', summary: '日工作统计', tags: ['produce-statistics'])]
#[DataResponse(description: '获取日工作统计成功')]
#[Permission(code: 'produce:statistics:daily', description: '日工作统计')]
public function daily(Request $request): Response
{
return Json::success('获取成功', [
'columns' => $this->dailyColumns(),
'items' => $this->service->daily($request->all()),
]);
}
private function monthlyColumns(string $month): array
{
$month = preg_match('/^\d{4}-\d{2}$/', $month) ? $month : date('Y-m');
$days = (int) date('t', strtotime($month . '-01'));
return array_map(static fn (int $day): array => [
'key' => (string) $day,
'label' => str_pad((string) $day, 2, '0', STR_PAD_LEFT),
], range(1, $days));
}
private function dailyColumns(): array
{
return array_map(static fn (int $hour): array => [
'key' => str_pad((string) $hour, 2, '0', STR_PAD_LEFT) . ':00',
'label' => str_pad((string) $hour, 2, '0', STR_PAD_LEFT) . ':00',
], range(0, 23));
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,227 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\appapi\controller;
use madong\swagger\annotation\response\DataResponse;
use madong\swagger\annotation\response\SimpleResponse;
use madong\swagger\attribute\AllowAnonymous;
use OpenApi\Attributes as OA;
use plugin\produce\app\api\controller\DataEntryController as WebDataEntryController;
use plugin\produce\app\service\admin\RepairRecordService;
use support\Request;
use support\Response;
#[OA\Tag(name: 'produce-app')]
final class DataEntryController
{
public function __construct(private WebDataEntryController $delegate)
{
}
#[OA\Get(path: '/produce/process', summary: 'APP 获取工序下拉', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function processOptions(Request $request): Response
{
return $this->delegate->processOptions($request);
}
#[OA\Get(path: '/produce/process-step', summary: 'APP 获取步骤下拉', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function stepOptions(Request $request): Response
{
return $this->delegate->stepOptions($request);
}
#[OA\Get(path: '/produce/step-status', summary: 'APP 获取状态下拉', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function statusOptions(Request $request): Response
{
return $this->delegate->statusOptions($request);
}
#[OA\Get(path: '/produce/material/lookup', summary: 'APP 按商品编码查询物料', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function materialLookup(Request $request): Response
{
return $this->delegate->materialLookup($request);
}
#[OA\Get(path: '/produce/scanapp/material-category', summary: 'APP 获取物料分类选项', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function scanAppMaterialCategory(Request $request): Response
{
return $this->delegate->scanAppMaterialCategory($request);
}
#[OA\Get(path: '/produce/hardware-fault-description/options', summary: 'APP 按物料分类获取硬件故障描述', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function hardwareFaultDescriptionOptions(Request $request): Response
{
return $this->delegate->hardwareFaultDescriptionOptions($request);
}
#[OA\Get(path: '/produce/config/data-entry', summary: 'APP 获取扫码输入页配置', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function dataEntryConfig(Request $request): Response
{
return $this->delegate->dataEntryConfig($request);
}
#[OA\Get(path: '/produce/member-user/check', summary: 'APP 校验用户编码对应会员', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function checkMemberUser(Request $request): Response
{
return $this->delegate->checkMemberUser($request);
}
#[OA\Get(path: '/produce/query/records', summary: 'APP 查询生产记录', tags: ['produce-app'])]
#[DataResponse(description: '查询成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function queryRecords(Request $request): Response
{
return $this->delegate->queryRecords($request);
}
#[OA\Get(path: '/produce/query/timeline', summary: 'APP 查询订单生产时间线', tags: ['produce-app'])]
#[DataResponse(description: '查询成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function queryTimeline(Request $request): Response
{
return $this->delegate->queryTimeline($request);
}
#[OA\Get(path: '/produce/scan-data', summary: 'APP 最近订单扫码记录', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function recentRecords(Request $request): Response
{
return $this->delegate->recentRecords($request);
}
#[OA\Get(path: '/produce/scan-data/statistics', summary: 'APP 订单扫码统计', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function statistics(Request $request): Response
{
return $this->delegate->statistics($request);
}
#[OA\Get(path: '/produce/scan-data/user-code-stats', summary: 'APP 用户扫码统计', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function userCodeStats(Request $request): Response
{
return $this->delegate->userCodeStats($request);
}
#[OA\Post(path: '/produce/scan-data/record', summary: 'APP 提交订单扫码记录', tags: ['produce-app'])]
#[SimpleResponse(description: '录入成功')]
public function record(Request $request): Response
{
return $this->delegate->record($request);
}
#[OA\Get(path: '/produce/exception/settings', summary: 'APP 获取异常设置', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function exceptionSettings(Request $request): Response
{
return $this->delegate->exceptionSettings($request);
}
#[OA\Get(path: '/produce/exception/statistics', summary: 'APP 获取异常统计', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function exceptionStatistics(Request $request): Response
{
return $this->delegate->exceptionStatistics($request);
}
#[OA\Get(path: '/produce/exception/recent', summary: 'APP 获取最近异常记录', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function recentExceptions(Request $request): Response
{
return $this->delegate->recentExceptions($request);
}
#[OA\Get(path: '/produce/exception/order-check', summary: 'APP 校验异常提报单号', tags: ['produce-app'])]
#[DataResponse(description: '校验成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function checkExceptionOrder(Request $request): Response
{
return $this->delegate->checkExceptionOrder($request);
}
#[OA\Get(path: '/produce/repair-record/tasks', summary: 'APP 获取待维修任务列表', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function repairTasks(Request $request): Response
{
return $this->delegate->repairTasks($request);
}
#[OA\Get(path: '/produce/repair-record/statistics', summary: 'APP 获取维修统计', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function repairStatistics(Request $request): Response
{
return $this->delegate->repairStatistics($request);
}
#[OA\Get(path: '/produce/exception/repair-task', summary: 'APP 获取维修异常任务', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function repairTask(Request $request): Response
{
return $this->delegate->repairTask($request);
}
#[OA\Post(path: '/produce/repair-record/record', summary: 'APP 提交维修记录', tags: ['produce-app'])]
#[SimpleResponse(description: '提交成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function repairRecord(Request $request, RepairRecordService $repairRecordService): Response
{
return $this->delegate->repairRecord($request, $repairRecordService);
}
#[OA\Post(path: '/produce/exception/record', summary: 'APP 提交异常记录', tags: ['produce-app'])]
#[SimpleResponse(description: '提交成功')]
#[AllowAnonymous(requireToken: false, requirePermission: false, description: 'APP 公共接口')]
public function exceptionRecord(Request $request): Response
{
return $this->delegate->exceptionRecord($request);
}
#[OA\Get(path: '/produce/product-record/recent', summary: 'APP 最近整机记录', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function productRecentRecords(Request $request): Response
{
return $this->delegate->productRecentRecords($request);
}
#[OA\Get(path: '/produce/product-record/statistics', summary: 'APP 整机统计', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function productStatistics(Request $request): Response
{
return $this->delegate->productStatistics($request);
}
#[OA\Get(path: '/produce/product-record/user-code-stats', summary: 'APP 整机用户统计', tags: ['produce-app'])]
#[DataResponse(description: '获取成功')]
public function productUserCodeStats(Request $request): Response
{
return $this->delegate->productUserCodeStats($request);
}
#[OA\Post(path: '/produce/product-record/record', summary: 'APP 提交整机记录', tags: ['produce-app'])]
#[SimpleResponse(description: '录入成功')]
public function productRecord(Request $request): Response
{
return $this->delegate->productRecord($request);
}
}
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\ExceptionRecord;
class ExceptionRecordDao extends BaseDao
{
protected function setModel(): string
{
return ExceptionRecord::class;
}
protected function getKeywordFields(): array
{
return ['order_no', 'user_code', 'reporter', 'type_name', 'reason_name', 'issue_name', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['createds']));
$order = $order ?: 'reported_at desc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$keyword = '%' . $where['keyword'] . '%';
$query->where(function (Builder $builder) use ($keyword) {
$builder->where('order_no', 'like', $keyword)
->orWhere('user_code', 'like', $keyword)
->orWhere('reporter', 'like', $keyword)
->orWhere('type_name', 'like', $keyword)
->orWhere('reason_name', 'like', $keyword)
->orWhere('issue_name', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
foreach (['type_code', 'reason_code', 'issue_code', 'status'] as $field) {
if (($where[$field] ?? '') !== '') {
$query->where($field, $where[$field]);
}
}
if (!empty($where['reported_at_range']) && is_array($where['reported_at_range']) && count($where['reported_at_range']) === 2) {
$query->whereBetween('reported_at', [
strtotime((string) $where['reported_at_range'][0] . ' 00:00:00'),
strtotime((string) $where['reported_at_range'][1] . ' 23:59:59'),
]);
}
return $query;
}
}
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use plugin\produce\app\model\ExceptionSetting;
class ExceptionSettingDao extends BaseDao
{
protected function setModel(): string
{
return ExceptionSetting::class;
}
protected function getKeywordFields(): array
{
return ['code', 'name', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['parent', 'createds']));
$order = $order ?: 'setting_type asc, parent_id asc, sort asc, id asc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
{
$with = array_unique(array_merge($with ?? [], ['parent', 'createds']));
return parent::get($id, $field, $with, $order, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$keyword = '%' . $where['keyword'] . '%';
$query->where(function (Builder $builder) use ($keyword) {
$builder->where('code', 'like', $keyword)
->orWhere('name', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
foreach (['setting_type', 'parent_id', 'is_enabled'] as $field) {
if (($where[$field] ?? '') !== '') {
$query->where($field, $where[$field]);
}
}
return $query;
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use plugin\produce\app\model\HardwareFaultDescription;
class HardwareFaultDescriptionDao extends BaseDao
{
protected function setModel(): string
{
return HardwareFaultDescription::class;
}
protected function getKeywordFields(): array
{
return ['description', 'remark'];
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use plugin\produce\app\model\MaterialCategory;
class MaterialCategoryDao extends BaseDao
{
protected function setModel(): string
{
return MaterialCategory::class;
}
protected function getKeywordFields(): array
{
return ['category_name'];
}
}
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\Material;
class MaterialDao extends BaseDao
{
protected function setModel(): string
{
return Material::class;
}
protected function getKeywordFields(): array
{
return ['product_code', 'product_name'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
return parent::selectList($where, $field, $page, $limit, $order ?: 'id desc', array_unique(array_merge($with, ['category'])), $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$keyword = '%' . $where['keyword'] . '%';
$query->where(function (Builder $builder) use ($keyword) {
$builder->where('product_code', 'like', $keyword)
->orWhere('product_name', 'like', $keyword);
});
}
if (($where['category_id'] ?? '') !== '') {
$query->where('category_id', $where['category_id']);
}
return $query;
}
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\Process;
class ProcessDao extends BaseDao
{
protected function setModel(): string
{
return Process::class;
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$query = $this->selectModel($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
$query->withCount(['steps as step_count']);
if ($page > 0 && $limit > 0) {
return $query->paginate($limit, ['*'], 'page', $page)->getCollection();
}
return $query->get();
}
protected function getKeywordFields(): array
{
return ['process_code', 'process_name', 'description'];
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\ProcessStep;
class ProcessStepDao extends BaseDao
{
protected function setModel(): string
{
return ProcessStep::class;
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
return parent::selectList($where, $field, $page, $limit, $order, ['process'], $search, $withoutScopes);
}
protected function getKeywordFields(): array
{
return ['step_code', 'step_name', 'description'];
}
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use plugin\produce\app\model\ProduceConfig;
class ProduceConfigDao extends BaseDao
{
protected function setModel(): string
{
return ProduceConfig::class;
}
protected function getKeywordFields(): array
{
return ['group_code', 'code', 'name', 'remark'];
}
public function getByGroupCode(string $groupCode): array
{
$items = $this->getModel()::query()
->where('group_code', $groupCode)
->orderBy('sort')
->orderBy('id')
->get();
$result = [];
foreach ($items as $item) {
$result[$item->code] = $item->content;
}
return $result;
}
public function batchSave(string $groupCode, array $configs): bool
{
$timestamp = time();
foreach ($configs as $config) {
$this->getModel()::query()->updateOrCreate(
[
'group_code' => $groupCode,
'code' => (string) ($config['code'] ?? ''),
],
[
'name' => (string) ($config['name'] ?? ''),
'content' => is_scalar($config['content'] ?? null) || $config['content'] === null
? ($config['content'] ?? null)
: json_encode($config['content'], JSON_UNESCAPED_UNICODE),
'sort' => (int) ($config['sort'] ?? 0),
'remark' => (string) ($config['remark'] ?? ''),
'updated_at' => $timestamp,
]
);
}
return true;
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\ProductRecord;
class ProductRecordDao extends BaseDao
{
protected function setModel(): string
{
return ProductRecord::class;
}
protected function getKeywordFields(): array
{
return ['process_order_no', 'product_code', 'operator', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['process', 'step', 'status']));
$order = $order ?: 'created_at desc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$query->where(function (Builder $builder) use ($where) {
$keyword = '%' . $where['keyword'] . '%';
$builder->where('process_order_no', 'like', $keyword)
->orWhere('product_code', 'like', $keyword)
->orWhere('operator', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
if (($where['process_id'] ?? '') !== '') {
$query->where('process_id', $where['process_id']);
}
if (($where['step_id'] ?? '') !== '') {
$query->where('step_id', $where['step_id']);
}
if (($where['status_id'] ?? '') !== '') {
$query->where('status_id', $where['status_id']);
}
if (($where['scan_result'] ?? '') !== '') {
$query->where('scan_result', $where['scan_result']);
}
if (!empty($where['created_time_range']) && is_array($where['created_time_range']) && count($where['created_time_range']) === 2) {
$query->whereBetween('created_at', [strtotime((string) $where['created_time_range'][0]), strtotime((string) $where['created_time_range'][1])]);
}
return $query;
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use plugin\produce\app\model\RepairRecord;
class RepairRecordDao extends BaseDao
{
protected function setModel(): string
{
return RepairRecord::class;
}
protected function getKeywordFields(): array
{
return ['repair_no', 'order_no', 'product_code', 'product_name', 'fault_description', 'operator', 'remark'];
}
}
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use plugin\produce\app\model\RepairSetting;
class RepairSettingDao extends BaseDao
{
protected function setModel(): string
{
return RepairSetting::class;
}
protected function getKeywordFields(): array
{
return ['code', 'name', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['parent', 'createds']));
$order = $order ?: 'setting_type asc, parent_id asc, sort asc, id asc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
{
$with = array_unique(array_merge($with ?? [], ['parent', 'createds']));
return parent::get($id, $field, $with, $order, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$keyword = '%' . $where['keyword'] . '%';
$query->where(function (Builder $builder) use ($keyword) {
$builder->where('code', 'like', $keyword)
->orWhere('name', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
foreach (['setting_type', 'parent_id', 'is_enabled'] as $field) {
if (($where[$field] ?? '') !== '') {
$query->where($field, $where[$field]);
}
}
return $query;
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\ScanData;
class ScanDataDao extends BaseDao
{
protected function setModel(): string
{
return ScanData::class;
}
protected function getKeywordFields(): array
{
return ['order_no', 'user_code', 'operator', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['process', 'step', 'status']));
$order = $order ?: 'scan_time desc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$query->where(function (Builder $builder) use ($where) {
$keyword = '%' . $where['keyword'] . '%';
$builder->where('order_no', 'like', $keyword)
->orWhere('user_code', 'like', $keyword)
->orWhere('operator', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
if (($where['process_id'] ?? '') !== '') {
$query->where('process_id', $where['process_id']);
}
if (($where['step_id'] ?? '') !== '') {
$query->where('step_id', $where['step_id']);
}
if (($where['status_id'] ?? '') !== '') {
$query->where('status_id', $where['status_id']);
}
if (($where['scan_result'] ?? '') !== '') {
$query->where('scan_result', $where['scan_result']);
}
if (!empty($where['scan_time_range']) && is_array($where['scan_time_range']) && count($where['scan_time_range']) === 2) {
$query->whereBetween('scan_time', [strtotime((string) $where['scan_time_range'][0]), strtotime((string) $where['scan_time_range'][1])]);
}
return $query;
}
}
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use plugin\produce\app\model\SpecificRule;
class SpecificRuleDao extends BaseDao
{
protected function setModel(): string
{
return SpecificRule::class;
}
protected function getKeywordFields(): array
{
return ['rule_name', 'rule_pattern', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['createds']));
$order = $order ?: 'sort asc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
{
$with = array_unique(array_merge($with ?? [], ['createds']));
return parent::get($id, $field, $with, $order, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = $this->query();
if (($where['keyword'] ?? '') !== '') {
$query->where(function (Builder $builder) use ($where) {
$keyword = '%' . $where['keyword'] . '%';
$builder->where('rule_name', 'like', $keyword)
->orWhere('rule_pattern', 'like', $keyword)
->orWhere('remark', 'like', $keyword);
});
}
if (($where['rule_type'] ?? '') !== '') {
$query->where('rule_type', $where['rule_type']);
}
if (($where['is_enabled'] ?? '') !== '') {
$query->where('is_enabled', $where['is_enabled']);
}
return $query;
}
}
@@ -0,0 +1,115 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Builder;
use plugin\produce\app\model\StatusTransition;
class StatusTransitionDao extends BaseDao
{
protected function setModel(): string
{
return StatusTransition::class;
}
protected function getKeywordFields(): array
{
return ['trigger_event', 'description'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['step', 'fromStatus', 'toStatus']));
$order = $order ?: 'priority desc, sort asc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = parent::handleSearch($where, $isPage);
if (($where['step_id'] ?? '') !== '') {
$query->where('step_id', $where['step_id']);
}
if (($where['from_status_id'] ?? '') !== '') {
$query->where('from_status_id', $where['from_status_id']);
}
if (($where['to_status_id'] ?? '') !== '') {
$query->where('to_status_id', $where['to_status_id']);
}
if (($where['trigger_event'] ?? '') !== '') {
$query->where('trigger_event', $where['trigger_event']);
}
return $query;
}
public function getAutoTransitionsByStep(int|string $stepId, int|string $fromStatusId): array
{
return $this->getModel()::query()
->where('step_id', $stepId)
->where('from_status_id', $fromStatusId)
->where('auto_trigger', 1)
->where('status', 1)
->orderBy('priority', 'desc')
->orderBy('sort', 'asc')
->with(['toStatus:id,status_name'])
->get()
->map(function ($item) {
return [
'id' => $item->id,
'step_id' => $item->step_id,
'from_status_id' => $item->from_status_id,
'to_status_id' => $item->to_status_id,
'to_status_name' => $item->toStatus->status_name ?? '',
'trigger_event' => $item->trigger_event,
'event_config' => $item->event_config,
'priority' => $item->priority,
];
})
->toArray();
}
public function getAutoTransitions(int|string $stepId, int|string $fromStatusId, string $triggerEvent): array
{
return $this->getModel()::query()
->where('step_id', $stepId)
->where('from_status_id', $fromStatusId)
->where('trigger_event', $triggerEvent)
->where('auto_trigger', 1)
->where('status', 1)
->orderBy('priority', 'desc')
->orderBy('sort', 'asc')
->with(['toStatus:id,status_name'])
->get()
->map(function ($item) {
return [
'id' => $item->id,
'step_id' => $item->step_id,
'from_status_id' => $item->from_status_id,
'to_status_id' => $item->to_status_id,
'to_status_name' => $item->toStatus->status_name ?? '',
'trigger_event' => $item->trigger_event,
'event_config' => $item->event_config,
'priority' => $item->priority,
];
})
->toArray();
}
}
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Builder;
use plugin\produce\app\model\StepRelation;
class StepRelationDao extends BaseDao
{
protected function setModel(): string
{
return StepRelation::class;
}
protected function getKeywordFields(): array
{
return ['relation_type', 'description'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['fromStep', 'toStep']));
$order = $order ?: 'priority asc, sort asc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = parent::handleSearch($where, $isPage);
if (($where['from_step_id'] ?? '') !== '') {
$query->where('from_step_id', $where['from_step_id']);
}
if (($where['to_step_id'] ?? '') !== '') {
$query->where('to_step_id', $where['to_step_id']);
}
if (($where['relation_type'] ?? '') !== '') {
$query->where('relation_type', $where['relation_type']);
}
return $query;
}
public function getPreviousSteps(int|string $currentStepId): array
{
return $this->getModel()::query()
->where('to_step_id', $currentStepId)
->where('status', 1)
->orderBy('priority', 'asc')
->orderBy('sort', 'asc')
->get(['id', 'from_step_id', 'to_step_id', 'relation_type'])
->toArray();
}
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Collection;
use plugin\produce\app\model\StepStatus;
class StepStatusDao extends BaseDao
{
protected function setModel(): string
{
return StepStatus::class;
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
return parent::selectList($where, $field, $page, $limit, $order, ['step'], $search, $withoutScopes);
}
protected function getKeywordFields(): array
{
return ['status_code', 'status_name', 'description'];
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\dao;
use core\base\BaseDao;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use plugin\produce\app\model\TransitionLog;
class TransitionLogDao extends BaseDao
{
protected function setModel(): string
{
return TransitionLog::class;
}
protected function getKeywordFields(): array
{
return ['work_order_no', 'trigger_user', 'error_message', 'remark'];
}
public function selectList(
array $where,
string|array $field = '*',
int $page = 0,
int $limit = 0,
string $order = '',
array $with = [],
bool $search = false,
?array $withoutScopes = null
): ?Collection {
$with = array_unique(array_merge($with, ['step', 'transition', 'fromStatus', 'toStatus']));
$order = $order ?: 'created_at desc, id desc';
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
}
public function get($id, ?array $field = null, ?array $with = [], string $order = '', ?array $withoutScopes = null): ?Model
{
$with = array_unique(array_merge($with ?? [], ['step', 'transition', 'fromStatus', 'toStatus']));
return parent::get($id, $field, $with, $order, $withoutScopes);
}
public function handleSearch(array $where, bool $isPage = true): Builder
{
$query = parent::handleSearch($where, $isPage);
if (($where['step_id'] ?? '') !== '') {
$query->where('step_id', $where['step_id']);
}
if (($where['trigger_event'] ?? '') !== '') {
$query->where('trigger_event', $where['trigger_event']);
}
if (($where['is_success'] ?? '') !== '') {
$query->where('is_success', $where['is_success']);
}
return $query;
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use app\model\system\Admin;
use core\base\BaseModel as CoreBaseModel;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
abstract class BaseModel extends CoreBaseModel
{
use SoftDeletes;
protected $appends = ['created_date', 'updated_date', 'created_name', 'updated_name'];
public function createds(): HasOne
{
return $this->hasOne(Admin::class, 'id', 'created_by')->select('id', 'real_name as created_name');
}
public function updateds(): HasOne
{
return $this->hasOne(Admin::class, 'id', 'updated_by')->select('id', 'real_name as updated_name');
}
public function getCreatedNameAttribute(): string
{
return $this->createds?->created_name ?? '';
}
public function getUpdatedNameAttribute(): string
{
return $this->updateds?->updated_name ?? '';
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
class ExceptionRecord extends BaseModel
{
protected $table = 'produce_exception_record';
protected $appends = ['reported_date', 'handled_date', 'status_name'];
protected static function booted(): void
{
static::creating(function (self $model) {
if (empty($model->reported_at)) {
$model->reported_at = time();
}
});
}
protected $fillable = [
'id',
'order_no',
'user_code',
'reporter',
'reporter_id',
'type_id',
'type_code',
'type_name',
'reason_id',
'reason_code',
'reason_name',
'issue_id',
'issue_code',
'issue_name',
'images',
'remark',
'status',
'handler',
'handler_id',
'handled_at',
'reported_at',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'images' => 'array',
'status' => 'integer',
'handled_at' => 'integer',
'reported_at' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getReportedDateAttribute(): ?string
{
return $this->reported_at ? date('Y-m-d H:i:s', (int) $this->reported_at) : null;
}
public function getHandledDateAttribute(): ?string
{
return $this->handled_at ? date('Y-m-d H:i:s', (int) $this->handled_at) : null;
}
public function getStatusNameAttribute(): string
{
return match ((int) $this->status) {
1 => '处理中',
2 => '已处理',
default => '待处理',
};
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ExceptionSetting extends BaseModel
{
protected $table = 'produce_exception_setting';
protected $appends = ['parent_name'];
protected $fillable = [
'id',
'parent_id',
'setting_type',
'code',
'name',
'sort',
'is_enabled',
'remark',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'sort' => 'integer',
'is_enabled' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id', 'id')->withTrashed();
}
public function getParentNameAttribute(): string
{
return (string) ($this->parent?->name ?? '');
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use plugin\produce\app\model\BaseModel;
use plugin\produce\app\model\MaterialCategory;
class HardwareFaultDescription extends BaseModel
{
protected $table = 'produce_hardware_fault_description';
protected $appends = ['created_date', 'updated_date', 'category_name'];
protected $fillable = [
'id', 'category_id', 'description', 'use_count', 'is_enabled', 'remark',
'created_by', 'updated_by', 'created_at', 'updated_at', 'deleted_at',
];
protected $casts = [
'use_count' => 'integer',
'is_enabled' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function category(): BelongsTo
{
return $this->belongsTo(MaterialCategory::class, 'category_id', 'id')->withTrashed();
}
public function getCategoryNameAttribute(): string
{
return (string) ($this->category?->category_name ?? '');
}
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Material extends BaseModel
{
protected $table = 'produce_material';
protected $appends = ['created_date', 'updated_date', 'category_name'];
protected $fillable = [
'id',
'category_id',
'product_code',
'product_name',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function category(): BelongsTo
{
return $this->belongsTo(MaterialCategory::class, 'category_id', 'id')->withTrashed();
}
public function getCategoryNameAttribute(): string
{
return (string) ($this->category?->category_name ?? '');
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class MaterialCategory extends BaseModel
{
protected $table = 'produce_material_category';
protected $fillable = [
'id',
'category_name',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getNameAttribute(): string
{
return (string) $this->category_name;
}
public function materials(): HasMany
{
return $this->hasMany(Material::class, 'category_id', 'id');
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Process extends BaseModel
{
protected $table = 'produce_process';
protected $fillable = [
'id',
'process_code',
'process_name',
'description',
'sort',
'status',
'step_count',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'sort' => 'integer',
'status' => 'integer',
'step_count' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getNameAttribute(): string
{
return (string) $this->process_name;
}
public function steps(): HasMany
{
return $this->hasMany(ProcessStep::class, 'process_id', 'id');
}
}
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ProcessStep extends BaseModel
{
protected $table = 'produce_process_step';
protected $fillable = [
'id',
'process_id',
'step_code',
'step_name',
'description',
'sort',
'status',
'prerequisite_steps',
'prerequisite_mode',
'prerequisite_require_final',
'allow_repeat_scan',
'repeat_scan_statuses',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'process_id' => 'integer',
'sort' => 'integer',
'status' => 'integer',
'prerequisite_steps' => 'array',
'prerequisite_require_final' => 'integer',
'allow_repeat_scan' => 'integer',
'repeat_scan_statuses' => 'array',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getNameAttribute(): string
{
return (string) $this->step_name;
}
public function process(): BelongsTo
{
return $this->belongsTo(Process::class, 'process_id', 'id');
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
class ProduceConfig extends BaseModel
{
protected $table = 'produce_config';
protected $fillable = [
'id',
'group_code',
'code',
'name',
'content',
'sort',
'remark',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'sort' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getNameAttribute(): string
{
return (string) $this->name;
}
}
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ProductRecord extends BaseModel
{
protected $table = 'produce_product_record';
protected $appends = ['created_date', 'updated_date', 'process_name', 'step_name', 'status_name'];
protected $fillable = [
'id',
'process_order_no',
'product_code',
'quantity',
'process_id',
'step_id',
'status_id',
'user_code',
'operator',
'operator_id',
'scan_result',
'remark',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'quantity' => 'integer',
'scan_result' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function process(): BelongsTo
{
return $this->belongsTo(Process::class, 'process_id', 'id')->withTrashed();
}
public function step(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'step_id', 'id')->withTrashed();
}
public function status(): BelongsTo
{
return $this->belongsTo(StepStatus::class, 'status_id', 'id')->withTrashed();
}
public function getProcessNameAttribute(): string
{
return (string) ($this->process?->process_name ?? '');
}
public function getStepNameAttribute(): string
{
return (string) ($this->step?->step_name ?? '');
}
public function getStatusNameAttribute(): string
{
return (string) ($this->status?->status_name ?? '');
}
public function getCreatedDateAttribute(): ?string
{
return $this->created_at ? date('Y-m-d H:i:s', (int) $this->created_at) : null;
}
public function getUpdatedDateAttribute(): ?string
{
return $this->updated_at ? date('Y-m-d H:i:s', (int) $this->updated_at) : null;
}
}
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use plugin\produce\app\model\BaseModel;
use plugin\produce\app\model\MaterialCategory;
class RepairRecord extends BaseModel
{
protected $table = 'produce_repair_record';
protected $appends = [
'created_date', 'updated_date', 'fault_description_name', 'fault_description_ids', 'fault_descriptions', 'repaired_date', 'exception_type_name',
'part_category', 'part_code', 'part_name', 'part_fault', 'part_quantity', 'part_source',
'order_product', 'repair_result_name', 'responsible_operator_names',
];
protected $with = ['exception'];
protected $fillable = [
'id', 'repair_no', 'exception_id', 'exception_reason', 'exception_issue', 'order_no', 'product_code', 'product_name', 'category_id', 'category_ids', 'category_name', 'category_names',
'fault_description_id', 'fault_description', 'repair_result', 'parts', 'images', 'operation_fault_steps', 'responsible_operators', 'operator', 'repaired_at',
'remark', 'created_by', 'updated_by', 'created_at', 'updated_at', 'deleted_at',
];
protected $casts = [
'category_ids' => 'array',
'category_names' => 'array',
'parts' => 'array',
'images' => 'array',
'operation_fault_steps' => 'array',
'responsible_operators' => 'array',
'repaired_at' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function category(): BelongsTo
{
return $this->belongsTo(MaterialCategory::class, 'category_id', 'id')->withTrashed();
}
public function exception(): BelongsTo
{
return $this->belongsTo(ExceptionRecord::class, 'exception_id', 'id')->withTrashed();
}
public function getExceptionTypeNameAttribute(): string
{
return (string) ($this->exception?->type_name ?? '');
}
public function faultDescription(): BelongsTo
{
return $this->belongsTo(HardwareFaultDescription::class, 'fault_description_id', 'id')->withTrashed();
}
public function getFaultDescriptionNameAttribute(): string
{
return (string) $this->fault_description;
}
public function getOrderProductAttribute(): string
{
return implode('/', array_filter([(string) $this->order_no, (string) $this->product_code]));
}
public function getRepairResultNameAttribute(): string
{
return match ($this->repair_result) {
'material_defect' => '物料不良',
'operation_defect' => '作业不良',
'assembly_mismatch' => '搭配错误',
'process_defect' => '工艺不良',
'no_defect' => '不良不现',
default => (string) $this->repair_result,
};
}
public function getResponsibleOperatorNamesAttribute(): string
{
return implode("\n", array_filter(array_map(
static function (array $snapshot): string {
$step = (string) ($snapshot['step_name'] ?? '');
$operator = (string) ($snapshot['operator'] ?? $snapshot['user_code'] ?? '');
return implode('-', array_filter([$step, $operator]));
},
is_array($this->responsible_operators) ? $this->responsible_operators : [],
)));
}
public function getPartCategoryAttribute(): string
{
return $this->formatPartValues(static fn (array $part): string => (string) ($part['category_name'] ?? ''));
}
public function getPartCodeAttribute(): string
{
return $this->formatPartValues(static fn (array $part): string => (string) ($part['product_code'] ?? ''));
}
public function getPartNameAttribute(): string
{
return $this->formatPartValues(static fn (array $part): string => (string) ($part['product_name'] ?? ''));
}
public function getPartFaultAttribute(): string
{
return $this->formatPartValues(static function (array $part): string {
return implode('、', array_filter(array_map(
static fn (array $fault): string => (string) ($fault['description'] ?? ''),
is_array($part['fault_descriptions'] ?? null) ? $part['fault_descriptions'] : [],
)));
});
}
public function getPartQuantityAttribute(): string
{
return $this->formatPartValues(static fn (array $part): string => (string) ($part['quantity'] ?? 1));
}
public function getPartSourceAttribute(): string
{
return $this->formatPartValues(static function (array $part): string {
return match ($part['source'] ?? '') {
'new' => '新料',
'old', 'after_sale', 'after_sales', 'after-sale' => '售后',
'repair', 'refurbished' => '返修',
default => (string) ($part['source'] ?? '-'),
};
});
}
private function formatPartValues(callable $callback): string
{
return implode("\n", array_map(
static fn (array $part): string => $callback($part) ?: '-',
is_array($this->parts) ? $this->parts : [],
));
}
public function getFaultDescriptionIdsAttribute(): array
{
return $this->fault_description_id ? [$this->fault_description_id] : [];
}
public function getFaultDescriptionsAttribute(): array
{
return $this->fault_description ? [$this->fault_description] : [];
}
public function getRepairedDateAttribute(): ?string
{
return $this->repaired_at ? date('Y-m-d H:i:s', (int) $this->repaired_at) : null;
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class RepairSetting extends BaseModel
{
protected $table = 'produce_repair_setting';
protected $appends = ['parent_name'];
protected $fillable = [
'id',
'parent_id',
'setting_type',
'code',
'name',
'sort',
'is_enabled',
'remark',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'sort' => 'integer',
'is_enabled' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id', 'id')->withTrashed();
}
public function getParentNameAttribute(): string
{
return (string) ($this->parent?->name ?? '');
}
}
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ScanData extends BaseModel
{
protected $table = 'produce_scan_data';
protected $appends = ['scan_date', 'process_name', 'step_name', 'status_name'];
protected static function booted(): void
{
static::creating(function (self $model) {
if (empty($model->scan_time)) {
$model->scan_time = time();
}
});
}
protected $fillable = [
'id',
'order_no',
'quantity',
'user_code',
'operator',
'operator_id',
'process_id',
'step_id',
'status_id',
'scan_result',
'scan_time',
'remark',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'quantity' => 'integer',
'scan_result' => 'integer',
'scan_time' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function process(): BelongsTo
{
return $this->belongsTo(Process::class, 'process_id', 'id')->withTrashed();
}
public function step(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'step_id', 'id')->withTrashed();
}
public function status(): BelongsTo
{
return $this->belongsTo(StepStatus::class, 'status_id', 'id')->withTrashed();
}
public function getProcessNameAttribute(): string
{
return (string) ($this->process?->process_name ?? '');
}
public function getStepNameAttribute(): string
{
return (string) ($this->step?->step_name ?? '');
}
public function getStatusNameAttribute(): string
{
return (string) ($this->status?->status_name ?? '');
}
public function getScanDateAttribute(): ?string
{
return $this->scan_time ? date('Y-m-d H:i:s', (int) $this->scan_time) : null;
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class SpecificRule extends BaseModel
{
protected $table = 'produce_specific_rule';
protected $fillable = [
'id',
'rule_name',
'rule_pattern',
'rule_type',
'apply_mode',
'match_field',
'is_enabled',
'step_ids',
'sort',
'remark',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'rule_type' => 'integer',
'is_enabled' => 'integer',
'step_ids' => 'array',
'sort' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getNameAttribute(): string
{
return (string) $this->rule_name;
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class StatusTransition extends BaseModel
{
protected $table = 'produce_status_transition';
protected $fillable = [
'id',
'step_id',
'from_status_id',
'to_status_id',
'trigger_event',
'event_config',
'auto_trigger',
'priority',
'transition_type',
'side_effect_type',
'side_effect_config',
'description',
'sort',
'status',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'step_id' => 'integer',
'from_status_id' => 'integer',
'to_status_id' => 'integer',
'event_config' => 'array',
'auto_trigger' => 'integer',
'priority' => 'integer',
'side_effect_config' => 'array',
'sort' => 'integer',
'status' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function step(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'step_id', 'id');
}
public function fromStatus(): BelongsTo
{
return $this->belongsTo(StepStatus::class, 'from_status_id', 'id');
}
public function toStatus(): BelongsTo
{
return $this->belongsTo(StepStatus::class, 'to_status_id', 'id');
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class StepRelation extends BaseModel
{
protected $table = 'produce_step_relation';
protected $fillable = [
'id',
'from_step_id',
'to_step_id',
'relation_type',
'flow_condition',
'priority',
'description',
'sort',
'status',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'from_step_id' => 'integer',
'to_step_id' => 'integer',
'flow_condition' => 'array',
'priority' => 'integer',
'sort' => 'integer',
'status' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function fromStep(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'from_step_id', 'id');
}
public function toStep(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'to_step_id', 'id');
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class StepStatus extends BaseModel
{
protected $table = 'produce_step_status';
protected $fillable = [
'id',
'step_id',
'status_code',
'status_name',
'is_initial',
'is_final',
'description',
'sort',
'status',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'step_id' => 'integer',
'is_initial' => 'integer',
'is_final' => 'integer',
'sort' => 'integer',
'status' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function getNameAttribute(): string
{
return (string) $this->status_name;
}
public function step(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'step_id', 'id');
}
}
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class TransitionLog extends BaseModel
{
const UPDATED_AT = null;
protected $table = 'produce_transition_log';
protected $appends = ['created_date', 'created_name'];
protected $fillable = [
'id',
'work_order_id',
'work_order_no',
'step_id',
'transition_id',
'from_status_id',
'to_status_id',
'trigger_event',
'trigger_data',
'trigger_user',
'trigger_ip',
'is_auto',
'is_success',
'error_message',
'duration',
'remark',
'created_by',
'created_at',
'deleted_at',
];
protected $casts = [
'work_order_id' => 'integer',
'step_id' => 'integer',
'transition_id' => 'integer',
'from_status_id' => 'integer',
'to_status_id' => 'integer',
'trigger_data' => 'array',
'is_auto' => 'integer',
'is_success' => 'integer',
'duration' => 'integer',
'created_at' => 'integer',
'deleted_at' => 'integer',
];
public function step(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'step_id', 'id');
}
public function transition(): BelongsTo
{
return $this->belongsTo(StatusTransition::class, 'transition_id', 'id');
}
public function fromStatus(): BelongsTo
{
return $this->belongsTo(StepStatus::class, 'from_status_id', 'id');
}
public function toStatus(): BelongsTo
{
return $this->belongsTo(StepStatus::class, 'to_status_id', 'id');
}
}
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use Illuminate\Database\Query\Builder;
use plugin\produce\app\model\ExceptionRecord;
class ExceptionAnalysisService
{
public function overview(array $params): array
{
$query = $this->query($params);
return [
'total' => (clone $query)->count(),
'pending' => (clone $query)->where('status', 0)->count(),
'processing' => (clone $query)->where('status', 1)->count(),
'completed' => (clone $query)->where('status', 2)->count(),
'by_type' => $this->group($params, 'type_code', 'type_name'),
'by_reason' => $this->group($params, 'reason_code', 'reason_name'),
'by_issue' => $this->group($params, 'issue_code', 'issue_name'),
'by_date' => $this->byDate($params),
];
}
private function group(array $params, string $codeColumn, string $nameColumn): array
{
return $this->query($params)
->selectRaw("{$codeColumn} as code, {$nameColumn} as name, COUNT(*) as total")
->groupBy($codeColumn, $nameColumn)
->orderByDesc('total')
->orderBy($nameColumn)
->limit(20)
->get()
->map(static fn (object $item): array => [
'code' => (string) $item->code,
'name' => (string) $item->name,
'total' => (int) $item->total,
])
->all();
}
private function byDate(array $params): array
{
$model = new ExceptionRecord();
$connection = $model->getConnection();
$table = $connection->getTablePrefix() . $model->getTable();
return $this->query($params)
->selectRaw("DATE_FORMAT(FROM_UNIXTIME({$table}.reported_at), '%Y-%m-%d') as date, COUNT(*) as total")
->groupBy('date')
->orderBy('date')
->get()
->map(static fn (object $item): array => [
'date' => (string) $item->date,
'total' => (int) $item->total,
])
->all();
}
private function query(array $params): Builder
{
$model = new ExceptionRecord();
$query = $model->getConnection()->table($model->getTable())->whereNull('deleted_at');
foreach (['type_code', 'reason_code', 'issue_code', 'status'] as $field) {
if (($params[$field] ?? '') !== '') {
$query->where($field, $params[$field]);
}
}
if (!empty($params['reported_at_range']) && is_array($params['reported_at_range']) && count($params['reported_at_range']) === 2) {
$query->whereBetween('reported_at', [
strtotime((string) $params['reported_at_range'][0] . ' 00:00:00'),
strtotime((string) $params['reported_at_range'][1] . ' 23:59:59'),
]);
} else {
$query->whereBetween('reported_at', [strtotime('-29 days 00:00:00'), time()]);
}
return $query;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ExceptionRecordDao;
class ExceptionRecordService extends BaseService
{
public function __construct(ExceptionRecordDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ExceptionSettingDao;
class ExceptionSettingService extends BaseService
{
public function __construct(ExceptionSettingDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use PhpOffice\PhpSpreadsheet\IOFactory;
use plugin\produce\app\dao\HardwareFaultDescriptionDao;
use plugin\produce\app\model\HardwareFaultDescription;
use plugin\produce\app\model\MaterialCategory;
class HardwareFaultDescriptionService extends BaseService
{
public function __construct(HardwareFaultDescriptionDao $dao)
{
$this->dao = $dao;
}
public function importFromExcel(string $filePath): array
{
$sheet = IOFactory::load($filePath)->getActiveSheet();
$rows = $sheet->toArray('', true, true, false);
if (count($rows) < 2) {
throw new \InvalidArgumentException('导入文件至少应包含表头和一条硬件故障描述数据');
}
$headers = array_map(static fn ($value) => trim((string) $value), $rows[0]);
$indexes = array_flip($headers);
foreach (['分类', '描述'] as $header) {
if (!array_key_exists($header, $indexes)) {
throw new \InvalidArgumentException('导入表头必须包含:分类、描述');
}
}
return $this->transaction(function () use ($rows, $indexes) {
$created = 0;
$updated = 0;
$categories = [];
foreach (array_slice($rows, 1) as $rowNumber => $row) {
$categoryName = trim((string) ($row[$indexes['分类']] ?? ''));
$description = trim((string) ($row[$indexes['描述']] ?? ''));
if ($categoryName === '' && $description === '') {
continue;
}
if ($categoryName === '' || $description === '') {
throw new \InvalidArgumentException('第 ' . ($rowNumber + 2) . ' 行的分类、描述均不能为空');
}
$category = $categories[$categoryName] ?? null;
if (!$category) {
$category = MaterialCategory::query()->withTrashed()->where('category_name', $categoryName)->first();
if ($category?->trashed()) {
$category->restore();
}
$category ??= MaterialCategory::query()->create(['category_name' => $categoryName]);
$categories[$categoryName] = $category;
}
$faultDescription = HardwareFaultDescription::query()
->withTrashed()
->where('category_id', $category->id)
->where('description', $description)
->first();
if ($faultDescription) {
if ($faultDescription->trashed()) {
$faultDescription->restore();
}
$updated++;
continue;
}
HardwareFaultDescription::query()->create([
'category_id' => $category->id,
'description' => $description,
]);
$created++;
}
return ['created' => $created, 'updated' => $updated];
});
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\MaterialCategoryDao;
class MaterialCategoryService extends BaseService
{
public function __construct(MaterialCategoryDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use PhpOffice\PhpSpreadsheet\IOFactory;
use plugin\produce\app\dao\MaterialDao;
use plugin\produce\app\model\Material;
use plugin\produce\app\model\MaterialCategory;
class MaterialService extends BaseService
{
public function __construct(MaterialDao $dao)
{
$this->dao = $dao;
}
/**
* 从 Excel 导入物料;首行必须为:分类、商品编码、商品名称。
* 相同商品编码会更新分类和名称,以便重复导入。
*/
public function importFromExcel(string $filePath): array
{
$sheet = IOFactory::load($filePath)->getActiveSheet();
$rows = $sheet->toArray('', true, true, false);
if (count($rows) < 2) {
throw new \InvalidArgumentException('导入文件至少应包含表头和一条物料数据');
}
$headers = array_map(static fn ($value) => trim((string) $value), $rows[0]);
$indexes = array_flip($headers);
foreach (['分类', '商品编码', '商品名称'] as $header) {
if (!array_key_exists($header, $indexes)) {
throw new \InvalidArgumentException('导入表头必须包含:分类、商品编码、商品名称');
}
}
return $this->transaction(function () use ($rows, $indexes) {
$created = 0;
$updated = 0;
$categories = [];
foreach (array_slice($rows, 1) as $rowNumber => $row) {
$categoryName = trim((string) ($row[$indexes['分类']] ?? ''));
$productCode = trim((string) ($row[$indexes['商品编码']] ?? ''));
$productName = trim((string) ($row[$indexes['商品名称']] ?? ''));
if ($categoryName === '' && $productCode === '' && $productName === '') {
continue;
}
if ($categoryName === '' || $productCode === '' || $productName === '') {
throw new \InvalidArgumentException('第 ' . ($rowNumber + 2) . ' 行的分类、商品编码、商品名称均不能为空');
}
$category = $categories[$categoryName] ?? null;
if (!$category) {
$category = MaterialCategory::query()->withTrashed()->where('category_name', $categoryName)->first();
if ($category?->trashed()) {
$category->restore();
}
$category ??= MaterialCategory::query()->create(['category_name' => $categoryName]);
$categories[$categoryName] = $category;
}
$material = Material::query()->withTrashed()->where('product_code', $productCode)->first();
if ($material) {
if ($material->trashed()) {
$material->restore();
}
$material->fill(['category_id' => $category->id, 'product_name' => $productName])->save();
$updated++;
continue;
}
Material::query()->create([
'category_id' => $category->id,
'product_code' => $productCode,
'product_name' => $productName,
]);
$created++;
}
return ['created' => $created, 'updated' => $updated];
});
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ProcessDao;
class ProcessService extends BaseService
{
public function __construct(ProcessDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ProcessStepDao;
class ProcessStepService extends BaseService
{
public function __construct(ProcessStepDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ProduceConfigDao;
class ProduceConfigService extends BaseService
{
public function __construct(ProduceConfigDao $dao)
{
$this->dao = $dao;
}
public function getConfigByGroup(string $groupCode): array
{
return $this->dao->getByGroupCode($groupCode);
}
public function saveConfig(string $groupCode, array $configs): bool
{
return $this->dao->batchSave($groupCode, $configs);
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ProductRecordDao;
class ProductRecordService extends BaseService
{
public function __construct(ProductRecordDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\RepairRecordDao;
use plugin\produce\app\model\HardwareFaultDescription;
use plugin\produce\app\model\MaterialCategory;
use plugin\produce\app\model\RepairRecord;
class RepairRecordService extends BaseService
{
public function __construct(RepairRecordDao $dao)
{
$this->dao = $dao;
}
public function save(array $data): RepairRecord
{
return $this->transaction(function () use ($data) {
$data = $this->prepareData($data);
$record = RepairRecord::query()->create($data);
$this->changeFaultUsage($record->fault_description_id, 1);
return $record;
});
}
public function update(int|string $id, array $data): bool
{
return $this->transaction(function () use ($id, $data) {
$record = RepairRecord::query()->findOrFail($id);
$previousFaultId = $record->fault_description_id;
$data = $this->prepareData($data);
$record->fill($data)->save();
if ((string) $previousFaultId !== (string) $record->fault_description_id) {
$this->changeFaultUsage($previousFaultId, -1);
$this->changeFaultUsage($record->fault_description_id, 1);
}
return true;
});
}
public function deleteRecord(int|string $id): bool
{
return $this->transaction(function () use ($id) {
$record = RepairRecord::query()->findOrFail($id);
$this->changeFaultUsage($record->fault_description_id, -1);
return (bool) $record->delete();
});
}
private function prepareData(array $data): array
{
$hasCategoryIds = array_key_exists('category_ids', $data);
$categoryIds = array_values(array_unique(array_filter(array_map(static fn ($id): string => trim((string) $id), (array) ($data['category_ids'] ?? [])), static fn (string $id): bool => $id !== '')));
if ($hasCategoryIds) {
$data['category_ids'] = $categoryIds ?: null;
$data['category_id'] = $categoryIds[0] ?? null;
if (!$categoryIds) {
$data['category_names'] = null;
}
}
$categoryId = $data['category_id'] ?? null;
$faultId = $data['fault_description_id'] ?? null;
if (isset($data['repaired_at']) && $data['repaired_at'] !== null && (int) $data['repaired_at'] > 9999999999) {
$data['repaired_at'] = (int) floor((int) $data['repaired_at'] / 1000);
}
if (array_key_exists('category_id', $data) && !$categoryId) {
$data['category_name'] = null;
$data['category_names'] = null;
}
if (array_key_exists('fault_description_id', $data) && !$faultId) {
$data['fault_description'] = null;
}
if ($categoryIds) {
$categories = MaterialCategory::query()->withTrashed()->whereIn('id', $categoryIds)->get(['id', 'category_name'])->keyBy('id');
if ($categories->count() !== count($categoryIds)) {
throw new \InvalidArgumentException('物料分类不存在');
}
$data['category_names'] = array_map(static fn (string $id): string => (string) $categories[$id]->category_name, $categoryIds);
$data['category_name'] = $data['category_names'][0];
} elseif ($categoryId) {
$data['category_name'] = MaterialCategory::query()->withTrashed()->whereKey($categoryId)->value('category_name');
}
if ($faultId) {
$fault = HardwareFaultDescription::query()->withTrashed()->find($faultId);
if (!$fault) {
throw new \InvalidArgumentException('硬件故障描述不存在');
}
if ($categoryId && (string) $fault->category_id !== (string) $categoryId) {
throw new \InvalidArgumentException('硬件故障描述与物料分类不匹配');
}
$data['category_id'] = $fault->category_id;
$data['category_ids'] = [$fault->category_id];
$data['category_name'] = $fault->category?->category_name ?? $data['category_name'] ?? '';
$data['category_names'] = [$data['category_name']];
$data['fault_description'] = $fault->description;
}
if (isset($data['parts']) && is_string($data['parts'])) {
$data['parts'] = json_decode($data['parts'], true, 512, JSON_THROW_ON_ERROR);
}
return $data;
}
private function changeFaultUsage(int|string|null $faultId, int $delta): void
{
if (!$faultId) {
return;
}
$fault = HardwareFaultDescription::query()->withTrashed()->find($faultId);
if (!$fault) {
return;
}
$fault->use_count = max(0, (int) $fault->use_count + $delta);
$fault->save();
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\RepairSettingDao;
class RepairSettingService extends BaseService
{
public function __construct(RepairSettingDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\ScanDataDao;
class ScanDataService extends BaseService
{
public function __construct(ScanDataDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\SpecificRuleDao;
class SpecificRuleService extends BaseService
{
public function __construct(SpecificRuleDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\StatusTransitionDao;
class StatusTransitionService extends BaseService
{
public function __construct(StatusTransitionDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\StepRelationDao;
class StepRelationService extends BaseService
{
public function __construct(StepRelationDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\StepStatusDao;
class StepStatusService extends BaseService
{
public function __construct(StepStatusDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use core\base\BaseService;
use plugin\produce\app\dao\TransitionLogDao;
class TransitionLogService extends BaseService
{
public function __construct(TransitionLogDao $dao)
{
$this->dao = $dao;
}
}
@@ -0,0 +1,215 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\service\admin;
use Illuminate\Database\Query\Builder;
use plugin\produce\app\model\ProductRecord;
use plugin\produce\app\model\ScanData;
class WorkStatisticsService
{
public function monthly(array $params): array
{
$month = $this->normalizeMonth($params['month'] ?? null);
$days = (int) date('t', strtotime($month . '-01'));
$start = strtotime($month . '-01 00:00:00');
$end = strtotime(date('Y-m-t 23:59:59', $start));
$rows = $this->collectRows($params, $start, $end, static fn (string $column): string => "DATE_FORMAT(FROM_UNIXTIME({$column}), '%Y-%m-%d')");
return $this->formatRows($rows, $days, static fn (int $index): string => (string) $index);
}
public function daily(array $params): array
{
$date = $this->normalizeDate($params['date'] ?? null);
$start = strtotime($date . ' 00:00:00');
$end = strtotime($date . ' 23:59:59');
$rows = $this->collectRows($params, $start, $end, static fn (string $column): string => "HOUR(FROM_UNIXTIME({$column}))");
return $this->formatRows($rows, 24, static fn (int $index): string => str_pad((string) $index, 2, '0', STR_PAD_LEFT) . ':00');
}
private function collectRows(array $params, int $start, int $end, callable $periodExpression): array
{
$dataType = (string) ($params['data_type'] ?? 'all');
$rows = [];
if ($dataType === 'all' || $dataType === 'order') {
$rows = array_merge($rows, $this->queryScanData($params, $start, $end, $periodExpression)->get()->all());
}
if ($dataType === 'all' || $dataType === 'machine') {
$rows = array_merge($rows, $this->queryProductRecord($params, $start, $end, $periodExpression)->get()->all());
}
return $rows;
}
private function queryScanData(array $params, int $start, int $end, callable $periodExpression): Builder
{
$scanDataModel = new ScanData();
$connection = $scanDataModel->getConnection();
$scanDataTable = $scanDataModel->getTable();
$processTable = 'produce_process';
$stepTable = 'produce_process_step';
$query = $connection->table($scanDataTable)
->leftJoin($processTable, $processTable . '.id', '=', $scanDataTable . '.process_id')
->leftJoin($stepTable, $stepTable . '.id', '=', $scanDataTable . '.step_id')
->whereBetween($scanDataTable . '.scan_time', [$start, $end])
->whereNull($scanDataTable . '.deleted_at');
foreach (['process_id', 'step_id', 'scan_result'] as $field) {
if (($params[$field] ?? '') !== '') {
$query->where($scanDataTable . '.' . $field, $params[$field]);
}
}
foreach (['user_code', 'operator'] as $field) {
if (($params[$field] ?? '') !== '') {
$query->where($scanDataTable . '.' . $field, 'like', '%' . $params[$field] . '%');
}
}
foreach (['process_name' => $processTable . '.process_name', 'step_name' => $stepTable . '.step_name'] as $field => $column) {
if (($params[$field] ?? '') !== '') {
$query->where($column, 'like', '%' . $params[$field] . '%');
}
}
return $query->select([
$scanDataTable . '.user_code',
$scanDataTable . '.operator',
$connection->raw($connection->getTablePrefix() . $processTable . '.process_name as process_name'),
$connection->raw($connection->getTablePrefix() . $stepTable . '.step_name as step_name'),
])
->selectRaw($periodExpression($connection->getTablePrefix() . $scanDataTable . '.scan_time') . ' as period')
->selectRaw('SUM(' . $connection->getTablePrefix() . $scanDataTable . '.quantity) as amount')
->groupBy('user_code', 'operator', 'process_name', 'step_name', 'period')
->orderBy('user_code')
->orderBy('process_name')
->orderBy('step_name');
}
private function queryProductRecord(array $params, int $start, int $end, callable $periodExpression): Builder
{
$productRecordModel = new ProductRecord();
$connection = $productRecordModel->getConnection();
$productRecordTable = $productRecordModel->getTable();
$processTable = 'produce_process';
$stepTable = 'produce_process_step';
$query = $connection->table($productRecordTable)
->leftJoin($processTable, $processTable . '.id', '=', $productRecordTable . '.process_id')
->leftJoin($stepTable, $stepTable . '.id', '=', $productRecordTable . '.step_id')
->whereBetween($productRecordTable . '.created_at', [$start, $end])
->whereNull($productRecordTable . '.deleted_at');
foreach (['process_id', 'step_id', 'scan_result'] as $field) {
if (($params[$field] ?? '') !== '') {
$query->where($productRecordTable . '.' . $field, $params[$field]);
}
}
foreach (['user_code', 'operator'] as $field) {
if (($params[$field] ?? '') !== '') {
$query->where($productRecordTable . '.' . $field, 'like', '%' . $params[$field] . '%');
}
}
foreach (['process_name' => $processTable . '.process_name', 'step_name' => $stepTable . '.step_name'] as $field => $column) {
if (($params[$field] ?? '') !== '') {
$query->where($column, 'like', '%' . $params[$field] . '%');
}
}
return $query->select([
$productRecordTable . '.user_code',
$productRecordTable . '.operator',
$connection->raw($connection->getTablePrefix() . $processTable . '.process_name as process_name'),
$connection->raw($connection->getTablePrefix() . $stepTable . '.step_name as step_name'),
])
->selectRaw($periodExpression($connection->getTablePrefix() . $productRecordTable . '.created_at') . ' as period')
->selectRaw('SUM(' . $connection->getTablePrefix() . $productRecordTable . '.quantity) as amount')
->groupBy('user_code', 'operator', 'process_name', 'step_name', 'period')
->orderBy('user_code')
->orderBy('process_name')
->orderBy('step_name');
}
private function formatRows(iterable $rows, int $periodCount, callable $periodLabel): array
{
$grouped = [];
$summaryRows = [];
foreach ($rows as $row) {
$productionProcess = $this->formatProductionProcess((string) $row->process_name, (string) $row->step_name);
$key = implode('|', [(string) $row->user_code, (string) $row->operator, (string) $row->process_name, (string) $row->step_name]);
if (!isset($grouped[$key])) {
$grouped[$key] = [
'user_code' => $row->user_code,
'operator' => $row->operator,
'production_process' => $productionProcess,
'process_name' => $row->process_name,
'step_name' => $row->step_name,
'total' => 0,
];
for ($index = 1; $index <= $periodCount; $index++) {
$grouped[$key][$periodLabel($index)] = 0;
}
}
if (!isset($summaryRows[$productionProcess])) {
$summaryRows[$productionProcess] = [
'user_code' => '总计',
'operator' => '',
'production_process' => $productionProcess,
'process_name' => $row->process_name,
'step_name' => $row->step_name,
'total' => 0,
];
for ($index = 1; $index <= $periodCount; $index++) {
$summaryRows[$productionProcess][$periodLabel($index)] = 0;
}
}
$period = (string) $row->period;
$period = $periodCount === 24 ? str_pad($period, 2, '0', STR_PAD_LEFT) . ':00' : (string) ((int) substr($period, -2));
if (array_key_exists($period, $grouped[$key])) {
$amount = (int) $row->amount;
$grouped[$key][$period] += $amount;
$grouped[$key]['total'] += $amount;
$summaryRows[$productionProcess][$period] += $amount;
$summaryRows[$productionProcess]['total'] += $amount;
}
}
$items = array_values($grouped);
if ($items !== []) {
$items = array_merge($items, array_values($summaryRows));
}
return $items;
}
private function formatProductionProcess(string $processName, string $stepName): string
{
if ($processName !== '' && $stepName !== '') {
return $processName . '-' . $stepName;
}
return $processName !== '' ? $processName : $stepName;
}
private function normalizeMonth(mixed $month): string
{
$month = is_string($month) && preg_match('/^\d{4}-\d{2}$/', $month) ? $month : date('Y-m');
return date('Y-m', strtotime($month . '-01'));
}
private function normalizeDate(mixed $date): string
{
$date = is_string($date) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $date) ? $date : date('Y-m-d');
return date('Y-m-d', strtotime($date));
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class ExceptionRecordValidate extends BaseValidate
{
public function rules(): array
{
return [
'order_no' => ['required', 'max:100'],
'user_code' => ['nullable', 'max:50'],
'reporter' => ['nullable', 'max:100'],
'type_id' => ['nullable', 'integer'],
'type_code' => ['required', 'max:64'],
'type_name' => ['required', 'max:100'],
'reason_id' => ['nullable', 'integer'],
'reason_code' => ['required', 'max:64'],
'reason_name' => ['required', 'max:100'],
'issue_id' => ['nullable', 'integer'],
'issue_code' => ['nullable', 'max:64'],
'issue_name' => ['nullable', 'max:100'],
'images' => ['nullable'],
'remark' => ['nullable', 'max:65535'],
'status' => ['nullable', 'integer', 'in:0,1,2'],
'handler' => ['nullable', 'max:100'],
'handler_id' => ['nullable', 'integer'],
'handled_at' => ['nullable', 'integer'],
'reported_at' => ['nullable', 'integer'],
];
}
protected array $message = [
'order_no.required' => '单号或条码不能为空',
'order_no.max' => '单号或条码不能超过100个字符',
'user_code.max' => '提报人工号不能超过50个字符',
'reporter.max' => '提报人不能超过100个字符',
'type_id.integer' => '处理类型格式不正确',
'type_code.required' => '处理类型编码不能为空',
'type_code.max' => '处理类型编码不能超过64个字符',
'type_name.required' => '处理类型名称不能为空',
'type_name.max' => '处理类型名称不能超过100个字符',
'reason_id.integer' => '异常原因格式不正确',
'reason_code.required' => '异常原因编码不能为空',
'reason_code.max' => '异常原因编码不能超过64个字符',
'reason_name.required' => '异常原因名称不能为空',
'reason_name.max' => '异常原因名称不能超过100个字符',
'issue_id.integer' => '具体问题格式不正确',
'issue_code.max' => '具体问题编码不能超过64个字符',
'issue_name.max' => '具体问题名称不能超过100个字符',
'status.integer' => '处理状态格式不正确',
'status.in' => '处理状态值不正确',
'handler.max' => '处理人不能超过100个字符',
'handler_id.integer' => '处理人ID格式不正确',
'handled_at.integer' => '处理时间格式不正确',
'reported_at.integer' => '提报时间格式不正确',
];
protected array $scene = [
'store' => ['order_no', 'user_code', 'reporter', 'type_id', 'type_code', 'type_name', 'reason_id', 'reason_code', 'reason_name', 'issue_id', 'issue_code', 'issue_name', 'images', 'remark', 'status', 'handler', 'handler_id', 'handled_at', 'reported_at'],
'update' => ['order_no', 'user_code', 'reporter', 'type_id', 'type_code', 'type_name', 'reason_id', 'reason_code', 'reason_name', 'issue_id', 'issue_code', 'issue_name', 'images', 'remark', 'status', 'handler', 'handler_id', 'handled_at', 'reported_at'],
];
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class ExceptionSettingValidate extends BaseValidate
{
public function rules(): array
{
return [
'parent_id' => ['nullable', 'integer'],
'setting_type' => ['required', 'in:type,reason,issue'],
'code' => ['required', 'max:64'],
'name' => ['required', 'max:100'],
'sort' => ['nullable', 'integer', 'min:0'],
'is_enabled' => ['nullable', 'integer', 'in:0,1'],
'remark' => ['nullable', 'max:65535'],
];
}
protected array $message = [
'parent_id.integer' => '父级设置格式不正确',
'setting_type.required' => '设置类型不能为空',
'setting_type.in' => '设置类型值不正确',
'code.required' => '设置编码不能为空',
'code.max' => '设置编码不能超过64个字符',
'name.required' => '设置名称不能为空',
'name.max' => '设置名称不能超过100个字符',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'is_enabled.integer' => '启用状态格式不正确',
'is_enabled.in' => '启用状态值不正确',
'remark.max' => '备注内容过长',
];
protected array $scene = [
'store' => ['parent_id', 'setting_type', 'code', 'name', 'sort', 'is_enabled', 'remark'],
'update' => ['parent_id', 'setting_type', 'code', 'name', 'sort', 'is_enabled', 'remark'],
];
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class HardwareFaultDescriptionValidate extends BaseValidate
{
public function rules(): array
{
return [
'category_id' => ['required', 'integer'],
'description' => ['required', 'max:500'],
'is_enabled' => ['integer', 'in:0,1'],
'remark' => ['max:500'],
];
}
protected array $message = [
'category_id.required' => '请选择物料分类',
'category_id.integer' => '物料分类不正确',
'description.required' => '硬件故障描述不能为空',
'description.max' => '硬件故障描述不能超过500个字符',
'is_enabled.in' => '启用状态不正确',
'remark.max' => '备注不能超过500个字符',
];
protected array $scene = [
'store' => ['category_id', 'description', 'is_enabled', 'remark'],
'update' => ['category_id', 'description', 'is_enabled', 'remark'],
];
}
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class MaterialCategoryValidate extends BaseValidate
{
public function rules(): array
{
return ['category_name' => ['required', 'max:100']];
}
protected array $message = [
'category_name.required' => '分类名称不能为空',
'category_name.max' => '分类名称不能超过100个字符',
];
protected array $scene = [
'store' => ['category_name'],
'update' => ['category_name'],
];
}
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class MaterialValidate extends BaseValidate
{
public function rules(): array
{
return [
'category_id' => ['required'],
'product_code' => ['required', 'max:100'],
'product_name' => ['required', 'max:200'],
];
}
protected array $message = [
'category_id.required' => '请选择分类',
'product_code.required' => '商品编码不能为空',
'product_code.max' => '商品编码不能超过100个字符',
'product_name.required' => '商品名称不能为空',
'product_name.max' => '商品名称不能超过200个字符',
];
protected array $scene = [
'store' => ['category_id', 'product_code', 'product_name'],
'update' => ['category_id', 'product_code', 'product_name'],
];
}
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
use plugin\produce\app\model\ProcessStep;
class ProcessStepValidate extends BaseValidate
{
public function rules(): array
{
$id = request()->route?->param('id');
$processId = (string) (request()->input('process_id') ?? '');
return [
'process_id' => ['required', 'integer'],
'step_code' => [
'required',
'max:50',
Rule::unique(ProcessStep::class, 'step_code')
->where(fn ($query) => $query->where('process_id', $processId))
->ignore($id, 'id')
],
'step_name' => ['required', 'max:100'],
'description' => ['nullable', 'max:65535'],
'sort' => ['nullable', 'integer', 'min:0'],
'status' => ['nullable', 'integer', 'in:0,1'],
'prerequisite_steps' => ['nullable'],
'prerequisite_mode' => ['nullable', 'in:all,any,none'],
'prerequisite_require_final' => ['nullable', 'integer', 'in:0,1'],
'allow_repeat_scan' => ['nullable', 'integer', 'in:0,1'],
'repeat_scan_statuses' => ['nullable'],
];
}
protected array $message = [
'process_id.required' => '所属工序不能为空',
'process_id.integer' => '所属工序格式不正确',
'step_code.required' => '步骤编码不能为空',
'step_code.max' => '步骤编码不能超过50个字符',
'step_code.unique' => '步骤编码已存在',
'step_name.required' => '步骤名称不能为空',
'step_name.max' => '步骤名称不能超过100个字符',
'description.max' => '步骤描述内容过长',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'status.integer' => '状态格式不正确',
'status.in' => '状态值不正确',
'prerequisite_mode.in' => '前置步骤验证模式值不正确',
'prerequisite_require_final.integer' => '前置步骤终态要求格式不正确',
'prerequisite_require_final.in' => '前置步骤终态要求值不正确',
'allow_repeat_scan.integer' => '允许重复扫码格式不正确',
'allow_repeat_scan.in' => '允许重复扫码值不正确',
];
protected array $scene = [
'store' => ['process_id', 'step_code', 'step_name', 'description', 'sort', 'status', 'prerequisite_steps', 'prerequisite_mode', 'prerequisite_require_final', 'allow_repeat_scan', 'repeat_scan_statuses'],
'update' => ['process_id', 'step_code', 'step_name', 'description', 'sort', 'status', 'prerequisite_steps', 'prerequisite_mode', 'prerequisite_require_final', 'allow_repeat_scan', 'repeat_scan_statuses'],
];
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
use plugin\produce\app\model\Process;
class ProcessValidate extends BaseValidate
{
public function rules(): array
{
$id = request()->route?->param('id');
return [
'process_code' => ['required', 'max:50', Rule::unique(Process::class, 'process_code')->ignore($id, 'id')],
'process_name' => ['required', 'max:100'],
'description' => ['nullable', 'max:65535'],
'sort' => ['nullable', 'integer', 'min:0'],
'status' => ['nullable', 'integer', 'in:0,1'],
];
}
protected array $message = [
'process_code.required' => '工序编码不能为空',
'process_code.max' => '工序编码不能超过50个字符',
'process_code.unique' => '工序编码已存在',
'process_name.required' => '工序名称不能为空',
'process_name.max' => '工序名称不能超过100个字符',
'description.max' => '工序描述内容过长',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'status.integer' => '状态格式不正确',
'status.in' => '状态值不正确',
];
protected array $scene = [
'store' => ['process_code', 'process_name', 'description', 'sort', 'status'],
'update' => ['process_code', 'process_name', 'description', 'sort', 'status'],
];
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class ProductRecordValidate extends BaseValidate
{
public function rules(): array
{
return [
'process_order_no' => ['required', 'max:100'],
'product_code' => ['required', 'max:100'],
'quantity' => ['required', 'integer', 'min:1'],
'user_code' => ['required', 'max:50'],
'operator' => ['nullable', 'max:100'],
'process_id' => ['nullable', 'integer'],
'step_id' => ['nullable', 'integer'],
'status_id' => ['nullable', 'integer'],
'scan_result' => ['required', 'integer', 'in:0,1'],
'remark' => ['nullable', 'max:65535'],
];
}
protected array $message = [
'process_order_no.required' => '加工单号不能为空',
'process_order_no.max' => '加工单号不能超过100个字符',
'product_code.required' => '商品编码不能为空',
'product_code.max' => '商品编码不能超过100个字符',
'quantity.required' => '数量不能为空',
'quantity.integer' => '数量格式不正确',
'quantity.min' => '数量必须大于0',
'user_code.required' => '用户编码不能为空',
'user_code.max' => '用户编码不能超过50个字符',
'operator.max' => '操作人员不能超过100个字符',
'process_id.integer' => '工序格式不正确',
'step_id.integer' => '步骤格式不正确',
'status_id.integer' => '状态格式不正确',
'scan_result.required' => '扫码结果不能为空',
'scan_result.integer' => '扫码结果格式不正确',
'scan_result.in' => '扫码结果值不正确',
'remark.max' => '备注内容过长',
];
protected array $scene = [
'store' => ['process_order_no', 'product_code', 'quantity', 'user_code', 'operator', 'process_id', 'step_id', 'status_id', 'scan_result', 'remark'],
'update' => ['process_order_no', 'product_code', 'quantity', 'user_code', 'operator', 'process_id', 'step_id', 'status_id', 'scan_result', 'remark'],
];
}
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class RepairRecordValidate extends BaseValidate
{
public function rules(): array
{
return [
'repair_no' => ['required', 'max:100'],
'order_no' => ['max:100'],
'product_code' => ['max:100'],
'product_name' => ['max:200'],
'category_id' => ['integer'],
'category_ids' => ['array'],
'category_ids.*' => ['integer'],
'fault_description_id' => ['integer'],
'repair_result' => ['max:50'],
'operator' => ['max:100'],
'repaired_at' => ['integer'],
'remark' => ['max:1000'],
];
}
protected array $message = [
'repair_no.required' => '维修单号不能为空',
'repair_no.max' => '维修单号不能超过100个字符',
'order_no.max' => '订单号不能超过100个字符',
'product_code.max' => '商品编码不能超过100个字符',
'product_name.max' => '商品名称不能超过200个字符',
'category_id.integer' => '物料分类不正确',
'category_ids.array' => '物料分类集合格式不正确',
'category_ids.*.integer' => '物料分类不正确',
'fault_description_id.integer' => '硬件故障描述不正确',
'repair_result.max' => '维修判定不能超过50个字符',
'operator.max' => '维修人员不能超过100个字符',
'repaired_at.integer' => '维修时间不正确',
'remark.max' => '备注不能超过1000个字符',
];
protected array $scene = [
'store' => ['repair_no', 'order_no', 'product_code', 'product_name', 'category_id', 'category_ids', 'fault_description_id', 'repair_result', 'parts', 'operator', 'repaired_at', 'remark'],
'update' => ['repair_no', 'order_no', 'product_code', 'product_name', 'category_id', 'category_ids', 'fault_description_id', 'repair_result', 'parts', 'operator', 'repaired_at', 'remark'],
];
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class RepairSettingValidate extends BaseValidate
{
public function rules(): array
{
return [
'parent_id' => ['nullable', 'integer'],
'setting_type' => ['required', 'in:type,reason,issue'],
'code' => ['required', 'max:64'],
'name' => ['required', 'max:100'],
'sort' => ['nullable', 'integer', 'min:0'],
'is_enabled' => ['nullable', 'integer', 'in:0,1'],
'remark' => ['nullable', 'max:65535'],
];
}
protected array $message = [
'parent_id.integer' => '父级设置格式不正确',
'setting_type.required' => '设置类型不能为空',
'setting_type.in' => '设置类型值不正确',
'code.required' => '设置编码不能为空',
'code.max' => '设置编码不能超过64个字符',
'name.required' => '设置名称不能为空',
'name.max' => '设置名称不能超过100个字符',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'is_enabled.integer' => '启用状态格式不正确',
'is_enabled.in' => '启用状态值不正确',
'remark.max' => '备注内容过长',
];
protected array $scene = [
'store' => ['parent_id', 'setting_type', 'code', 'name', 'sort', 'is_enabled', 'remark'],
'update' => ['parent_id', 'setting_type', 'code', 'name', 'sort', 'is_enabled', 'remark'],
];
}
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class ScanDataValidate extends BaseValidate
{
public function rules(): array
{
return [
'order_no' => ['required', 'max:100'],
'quantity' => ['nullable', 'integer', 'min:1'],
'user_code' => ['required', 'max:50'],
'operator' => ['nullable', 'max:100'],
'process_id' => ['required', 'integer'],
'step_id' => ['required', 'integer'],
'status_id' => ['nullable', 'integer'],
'scan_result' => ['required', 'integer', 'in:0,1'],
'remark' => ['nullable', 'max:65535'],
];
}
protected array $message = [
'order_no.required' => '订单号不能为空',
'order_no.max' => '订单号不能超过100个字符',
'quantity.integer' => '本次数量格式不正确',
'quantity.min' => '本次数量必须大于0',
'user_code.required' => '用户编码不能为空',
'user_code.max' => '用户编码不能超过50个字符',
'operator.max' => '操作人员不能超过100个字符',
'process_id.required' => '工序不能为空',
'process_id.integer' => '工序格式不正确',
'step_id.required' => '步骤不能为空',
'step_id.integer' => '步骤格式不正确',
'status_id.integer' => '状态格式不正确',
'scan_result.required' => '扫码结果不能为空',
'scan_result.integer' => '扫码结果格式不正确',
'scan_result.in' => '扫码结果值不正确',
'remark.max' => '备注内容过长',
];
protected array $scene = [
'store' => ['order_no', 'quantity', 'user_code', 'operator', 'process_id', 'step_id', 'status_id', 'scan_result', 'remark'],
'update' => ['order_no', 'quantity', 'user_code', 'operator', 'process_id', 'step_id', 'status_id', 'scan_result', 'remark'],
];
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class SpecificRuleValidate extends BaseValidate
{
public function rules(): array
{
return [
'rule_name' => ['required', 'max:255'],
'rule_pattern' => ['required'],
'rule_type' => ['required', 'integer'],
'apply_mode' => ['required', 'in:order,machine,both'],
'match_field' => ['required', 'in:order_no,process_order_no,product_code,user_code'],
'is_enabled' => ['nullable', 'integer', 'in:0,1'],
'step_ids' => ['nullable'],
'sort' => ['nullable', 'integer', 'min:0'],
'remark' => ['nullable', 'max:65535'],
];
}
protected array $message = [
'rule_name.required' => '规则名称不能为空',
'rule_name.max' => '规则名称不能超过255个字符',
'rule_pattern.required' => '规则表达式不能为空',
'rule_type.required' => '规则类型不能为空',
'rule_type.integer' => '规则类型格式不正确',
'apply_mode.required' => '适用模式不能为空',
'apply_mode.in' => '适用模式值不正确',
'match_field.required' => '匹配字段不能为空',
'match_field.in' => '匹配字段值不正确',
'is_enabled.integer' => '启用状态格式不正确',
'is_enabled.in' => '启用状态值不正确',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'remark.max' => '备注内容过长',
];
protected array $scene = [
'store' => ['rule_name', 'rule_pattern', 'rule_type', 'apply_mode', 'match_field', 'is_enabled', 'step_ids', 'sort', 'remark'],
'update' => ['rule_name', 'rule_pattern', 'rule_type', 'apply_mode', 'match_field', 'is_enabled', 'step_ids', 'sort', 'remark'],
];
}
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
class StatusTransitionValidate extends BaseValidate
{
public function rules(): array
{
return [
'step_id' => ['required', 'integer'],
'from_status_id' => ['required', 'integer'],
'to_status_id' => ['required', 'integer', 'different:from_status_id'],
'trigger_event' => ['required', 'max:100', 'in:next_step_scan,scan_trigger,exception_trigger,manual_trigger,timer_trigger,complete_trigger'],
'event_config' => [
'nullable',
function (string $attribute, mixed $value, \Closure $fail) {
if ($value === null || $value === '') {
return;
}
if (is_array($value)) {
return;
}
if (!is_string($value)) {
$fail('事件配置必须为有效的JSON字符串');
return;
}
json_decode($value, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$fail('事件配置必须为有效的JSON字符串');
}
}
],
'auto_trigger' => ['nullable', 'integer', 'in:0,1'],
'priority' => ['nullable', 'integer', 'min:0'],
'transition_type' => ['required', 'max:20', 'in:primary,side_effect'],
'side_effect_type' => ['nullable', 'max:50', 'in:log,notify,update_field,trigger_event'],
'side_effect_config' => [
'nullable',
function (string $attribute, mixed $value, \Closure $fail) {
if ($value === null || $value === '') {
return;
}
if (is_array($value)) {
return;
}
if (!is_string($value)) {
$fail('副作用配置必须为有效的JSON字符串');
return;
}
json_decode($value, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$fail('副作用配置必须为有效的JSON字符串');
}
}
],
'description' => ['nullable', 'max:65535'],
'sort' => ['nullable', 'integer', 'min:0'],
'status' => ['nullable', 'integer', 'in:0,1'],
];
}
protected array $message = [
'step_id.required' => '所属步骤不能为空',
'step_id.integer' => '所属步骤格式不正确',
'from_status_id.required' => '源状态不能为空',
'from_status_id.integer' => '源状态格式不正确',
'to_status_id.required' => '目标状态不能为空',
'to_status_id.integer' => '目标状态格式不正确',
'to_status_id.different' => '目标状态不能与源状态相同',
'trigger_event.required' => '触发事件不能为空',
'trigger_event.max' => '触发事件长度不能超过100个字符',
'trigger_event.in' => '触发事件值不正确',
'auto_trigger.integer' => '自动触发格式不正确',
'auto_trigger.in' => '自动触发值不正确',
'priority.integer' => '优先级必须为整数',
'priority.min' => '优先级不能小于0',
'transition_type.required' => '转换类型不能为空',
'transition_type.max' => '转换类型长度不能超过20个字符',
'transition_type.in' => '转换类型值不正确',
'side_effect_type.max' => '副作用类型长度不能超过50个字符',
'side_effect_type.in' => '副作用类型值不正确',
'description.max' => '描述内容过长',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'status.integer' => '状态格式不正确',
'status.in' => '状态值不正确',
];
protected array $scene = [
'store' => ['step_id', 'from_status_id', 'to_status_id', 'trigger_event', 'event_config', 'auto_trigger', 'priority', 'transition_type', 'side_effect_type', 'side_effect_config', 'description', 'sort', 'status'],
'update' => ['step_id', 'from_status_id', 'to_status_id', 'trigger_event', 'event_config', 'auto_trigger', 'priority', 'transition_type', 'side_effect_type', 'side_effect_config', 'description', 'sort', 'status'],
];
}
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
use plugin\produce\app\model\StepRelation;
class StepRelationValidate extends BaseValidate
{
public function rules(): array
{
$id = request()->route?->param('id');
$fromStepId = (string) (request()->input('from_step_id') ?? '');
$toStepId = (string) (request()->input('to_step_id') ?? '');
$relationType = (string) (request()->input('relation_type') ?? 'normal');
return [
'from_step_id' => ['required', 'integer'],
'to_step_id' => ['required', 'integer', 'different:from_step_id'],
'relation_type' => [
'required',
'max:20',
Rule::in(['normal', 'exception']),
Rule::unique(StepRelation::class, 'relation_type')
->where(fn ($query) => $query
->where('from_step_id', $fromStepId)
->where('to_step_id', $toStepId)
)
->ignore($id, 'id')
],
'flow_condition' => [
'nullable',
function (string $attribute, mixed $value, \Closure $fail) {
if ($value === null || $value === '') {
return;
}
if (is_array($value)) {
return;
}
if (!is_string($value)) {
$fail('流转条件必须为有效的JSON字符串');
return;
}
json_decode($value, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$fail('流转条件必须为有效的JSON字符串');
}
}
],
'priority' => ['nullable', 'integer', 'min:0'],
'description' => ['nullable', 'max:65535'],
'sort' => ['nullable', 'integer', 'min:0'],
'status' => ['nullable', 'integer', 'in:0,1'],
];
}
protected array $message = [
'from_step_id.required' => '源步骤不能为空',
'from_step_id.integer' => '源步骤格式不正确',
'to_step_id.required' => '目标步骤不能为空',
'to_step_id.integer' => '目标步骤格式不正确',
'to_step_id.different' => '目标步骤不能与源步骤相同',
'relation_type.required' => '关系类型不能为空',
'relation_type.max' => '关系类型长度不能超过20个字符',
'relation_type.in' => '关系类型值不正确',
'relation_type.unique' => '该步骤关系已存在',
'priority.integer' => '优先级必须为整数',
'priority.min' => '优先级不能小于0',
'description.max' => '描述内容过长',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'status.integer' => '状态格式不正确',
'status.in' => '状态值不正确',
];
protected array $scene = [
'store' => ['from_step_id', 'to_step_id', 'relation_type', 'flow_condition', 'priority', 'description', 'sort', 'status'],
'update' => ['from_step_id', 'to_step_id', 'relation_type', 'flow_condition', 'priority', 'description', 'sort', 'status'],
];
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace plugin\produce\app\validate;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
use plugin\produce\app\model\StepStatus;
class StepStatusValidate extends BaseValidate
{
public function rules(): array
{
$id = request()->route?->param('id');
$stepId = (string) (request()->input('step_id') ?? '');
return [
'step_id' => ['required', 'integer'],
'status_code' => [
'required',
'max:50',
Rule::unique(StepStatus::class, 'status_code')
->where(fn ($query) => $query->where('step_id', $stepId))
->ignore($id, 'id')
],
'status_name' => ['required', 'max:100'],
'is_initial' => ['nullable', 'integer', 'in:0,1'],
'is_final' => ['nullable', 'integer', 'in:0,1'],
'description' => ['nullable', 'max:65535'],
'sort' => ['nullable', 'integer', 'min:0'],
'status' => ['nullable', 'integer', 'in:0,1'],
];
}
protected array $message = [
'step_id.required' => '所属步骤不能为空',
'step_id.integer' => '所属步骤格式不正确',
'status_code.required' => '状态编码不能为空',
'status_code.max' => '状态编码不能超过50个字符',
'status_code.unique' => '状态编码已存在',
'status_name.required' => '状态名称不能为空',
'status_name.max' => '状态名称不能超过100个字符',
'is_initial.integer' => '初始状态格式不正确',
'is_initial.in' => '初始状态值不正确',
'is_final.integer' => '终态格式不正确',
'is_final.in' => '终态值不正确',
'description.max' => '状态描述内容过长',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'status.integer' => '状态格式不正确',
'status.in' => '状态值不正确',
];
protected array $scene = [
'store' => ['step_id', 'status_code', 'status_name', 'is_initial', 'is_final', 'description', 'sort', 'status'],
'update' => ['step_id', 'status_code', 'status_name', 'is_initial', 'is_final', 'description', 'sort', 'status'],
];
}