177c3ae9b2
- 将 ProcessContext 中的 builder() 重命名为 createModifyBuilder() 并添加调用栈日志 - ProcessContextBuilder 中所有 with* 方法统一改为 set* 命名风格 - Flow 各节点及流程处理器中调用 builder() 替换为 createModifyBuilder() - 虚拟测试环境相关 ContextBuilder 中方法同步改名保持一致 - 优化流程节点中上下文修改代码调用,提升代码规范性 - 添加Config中加载自定义流程配置的占位注释及代码 - 无功能改动,纯代码风格及命名规范调整
119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace app\flow\strategies;
|
|
|
|
use app\flow\config\MorningMode;
|
|
use app\flow\config\MorningWashConfig;
|
|
use app\flow\context\ProcessContext;
|
|
use app\flow\nodes\ProcessNodeInterface;
|
|
use app\flow\context\bean\MorningWashStatus;
|
|
use app\utils\Logger;
|
|
|
|
/**
|
|
* 晨洗判断策略
|
|
* 根据配置判断是否需要晨洗
|
|
*/
|
|
class MorningWashStrategy extends AbstractStrategy
|
|
{
|
|
protected string $phase = 'before';
|
|
|
|
protected MorningWashConfig $morningWashConfig;
|
|
|
|
public function __construct(MorningWashConfig $config)
|
|
{
|
|
parent::__construct([]);
|
|
$this->morningWashConfig = $config;
|
|
Logger::debug("MorningWashStrategy 初始化完成");
|
|
}
|
|
|
|
/**
|
|
* 执行晨洗判断
|
|
*/
|
|
protected function doExecute(ProcessContext $context, ProcessNodeInterface $node): ProcessContext
|
|
{
|
|
$isEnd = $context->getCurrentStep() == '结束';
|
|
$needMorning = $this->checkNeedMorningWash($context) && $isEnd;
|
|
|
|
$morningWash = new MorningWashStatus(
|
|
needMorningWash: $needMorning,
|
|
morningWashed: !$needMorning,
|
|
startTime: $context->getMorningWash()->startTime,
|
|
todayWashRecords: $context->getMorningWash()->todayWashRecords
|
|
);
|
|
|
|
return $context->createModifyBuilder()->setMorningWash($morningWash)->build();
|
|
}
|
|
|
|
/**
|
|
* 检查是否需要晨洗
|
|
*/
|
|
protected function checkNeedMorningWash(ProcessContext $context): bool
|
|
{
|
|
return match ($this->morningWashConfig->mode) {
|
|
MorningMode::None => false,
|
|
MorningMode::All => true,
|
|
MorningMode::StorageTime => $this->checkByStorageTime($context),
|
|
MorningMode::DailyFirst => $this->checkByDailyFirst($context),
|
|
MorningMode::SpecificTypes => $this->checkBySpecificTypes($context),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 根据存储时间判断(义乌模式)
|
|
* 普通镜柜超过阈值小时需要晨洗,无菌镜柜免晨消
|
|
*/
|
|
protected function checkByStorageTime(ProcessContext $context): bool
|
|
{
|
|
$storageInTime = $context->getStorage()->inTime;
|
|
$lastActionType = $context->getPreviousAction()?->action_type_name;
|
|
$lastProcessName = $context->getPreviousAction()?->process_name;
|
|
|
|
// 如果最后一次操作是存储且已取出
|
|
if ($lastActionType === '存储' && $lastProcessName === '内镜取出') {
|
|
return false;
|
|
}
|
|
|
|
// 如果最后一次操作是存储且未取出,检查存储时间
|
|
if ($lastActionType === '存储' && $lastProcessName === '内镜放入' && $storageInTime) {
|
|
$storageHours = (time() - strtotime($storageInTime)) / 3600;
|
|
return $storageHours > $this->morningWashConfig->storageThreshold;
|
|
}
|
|
|
|
// 检查今天是否已有洗消记录
|
|
return $this->hasWashRecordToday($context);
|
|
}
|
|
|
|
/**
|
|
* 根据每天第一次判断(忠县模式)
|
|
*/
|
|
protected function checkByDailyFirst(ProcessContext $context): bool
|
|
{
|
|
return $this->hasWashRecordToday($context);
|
|
}
|
|
|
|
/**
|
|
* 检查今天是否已有洗消记录
|
|
*/
|
|
protected function hasWashRecordToday(ProcessContext $context): bool
|
|
{
|
|
return $context->getMorningWash()->todayWashRecords === 0;
|
|
}
|
|
|
|
/**
|
|
* 根据特定类型判断
|
|
*/
|
|
protected function checkBySpecificTypes(ProcessContext $context): bool
|
|
{
|
|
$specificTypes = $this->morningWashConfig->getExpand('specific_types', []);
|
|
return in_array($context->getEndoscope()->type, $specificTypes);
|
|
}
|
|
|
|
/**
|
|
* 获取策略名称
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return '晨洗判断策略(' . $this->morningWashConfig->mode->name . ')';
|
|
}
|
|
}
|