feat: 实现TCP Server

This commit is contained in:
zimoyin
2026-03-02 21:59:43 +08:00
parent 043306819b
commit a79dfae57d
144 changed files with 15785 additions and 140 deletions
+124
View File
@@ -0,0 +1,124 @@
<?php
namespace app\flow\config;
use app\repository\ProcessDurationRepository;
use app\utils\Logger;
/**
* 时间验证配置类
* 管理各流程步骤的最小时长要求(秒)
*/
class TimeValidationConfig extends AbstractConfig
{
/**
* 默认步骤时长
* 值 <= 0 表示该步骤不参与时间验证
*/
public array $durations = [
'手工洗' => [
'清洗' => 120,
'漂洗' => 60,
'消毒' => 300,
'终末漂洗' => 120,
'干燥' => 30,
'机洗' => 360,
],
'机洗' => [
'清洗' => 120,
'漂洗' => 60,
'消毒' => 300,
'终末漂洗' => 120,
'干燥' => 30,
'机洗' => 360,
],
'手工洗(加强)' => [
'清洗' => 60,
'漂洗' => 120,
'消毒' => 420,
'终末漂洗' => 120,
'干燥' => 30,
'机洗' => 360,
],
'机洗(加强)' => [
'清洗' => 60,
'漂洗' => 120,
'消毒' => 420,
'终末漂洗' => 120,
'干燥' => 30,
'机洗' => 360,
],
'手工洗(晨洗)' => [
'清洗' => 120,
'漂洗' => 60,
'消毒' => 300,
'终末漂洗' => 120,
'干燥' => 30,
'机洗' => 360,
],
'机洗(晨洗)' => [
'清洗' => 120,
'漂洗' => 60,
'消毒' => 300,
'终末漂洗' => 120,
'干燥' => 30,
'机洗' => 360,
],
];
public function __construct(array $durations = [])
{
if (empty($durations)) {
$this->durations = ProcessDurationRepository::new()->getProcessDurations();
Logger::debug("加载[time_validation]时间验证配置,来源: 数据库");
} else {
$this->durations = array_merge($this->durations, $durations);
Logger::debug("加载[time_validation]时间验证配置,来源: 自定义参数");
}
}
/**
* 获取指定步骤的时长(不存在则返回 0)
*/
public function getDuration(string $stepCode, string $processType = '手工洗'): int
{
$process = $this->durations[$processType];
if (!isset($process)) return 0;
return $process[$stepCode] ?? 0;
}
/**
* 设置指定步骤的时长
*/
public function setDuration(string $stepCode, int $seconds, string $processType = '手工洗'): self
{
$this->durations[$processType][$stepCode] = $seconds;
return $this;
}
/**
* 判断步骤是否参与时间验证
*/
public function hasStep(string $stepCode, string $processType = '手工洗'): bool
{
return array_key_exists($stepCode, $this->durations[$processType] ?? []);
}
/**
* 从数组创建(兼容旧配置格式 ['durations' => [...]]
*/
public static function create(array $config = []): self
{
$durations = $config['durations'] ?? $config;
if (!is_array($durations)) {
$durations = [];
}
$instance = new self($durations);
return $instance;
}
public function toArray(): array
{
return ['durations' => $this->durations];
}
}