Files
2026-03-08 22:58:56 +08:00

70 lines
1.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\repository;
use app\model\EctMetaFacilities;
use app\model\EctMetaProcess;
use app\model\EctMetaRfidreader;
/**
* 读卡器数据仓库
* 封装 ect_meta_rfidreader / ect_meta_facilities / ect_meta_process 的联合查询
*/
class ReaderRepository extends BaseRepository
{
public function __construct()
{
$this->model = new EctMetaRfidreader();
}
public static function new(): static
{
return new self();
}
/**
* 通过读卡器编号查询读卡器所在步骤信息
*
* 联合查询路径:
* ect_meta_rfidreader.reader_no
* → ect_meta_facilities.reader_id
* → ect_meta_process.process_id
* → process_name(步骤名称)
*
* @param string $readerNo 读卡器编号(大写)
* @return array{readerId: string, readerType: string}|null
* readerId = reader_id(读卡器ID
* readerType = process_name(该读卡器所在步骤,如"清洗")
*/
public function findReaderInfo(string $readerNo): ?array
{
$readerNo = strtoupper($readerNo);
$reader = EctMetaRfidreader::where('reader_no', $readerNo)
->select('reader_id')
->first();
if ($reader === null) {
return null;
}
$readerId = (string) $reader->reader_id;
$facility = EctMetaFacilities::where('reader_id', $readerId)
->select('process_id')
->first();
if ($facility === null) {
return ['readerId' => $readerId, 'readerType' => ''];
}
$process = EctMetaProcess::where('process_id', $facility->process_id)
->select('process_name')
->first();
$readerType = (string)$process?->process_name;
return ['readerId' => $readerId, 'readerType' => $readerType];
}
}