ylyPrinterKey = AdminRedisKey::ylyPrinterList(); $this->jdPrinterKey = AdminRedisKey::jdPrinterList(); } /** * 初始化打印机列表数据 * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ private function __initPrinterListData(): void { $printerList = $this->printerModel->get(); if ($printerList->isEmpty()) return; $ylyPrinterList = []; $jdPrinterList = []; foreach ($printerList->toArray() as $printer) { match ($printer['type']) { CateringCode::OPTION_PRINT_YLY => $ylyPrinterList[] = $printer, CateringCode::OPTION_PRINT_CODING => $jdPrinterList[] = $printer, }; } $this->delCache(); $this->redisCache->set($this->ylyPrinterKey, json_encode($ylyPrinterList),RedisCode::SYSTEM_DB); $this->redisCache->set($this->jdPrinterKey, json_encode($jdPrinterList),RedisCode::SYSTEM_DB); } /** * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function getYlyPrinter(): array { if (!$this->redisCache->exists($this->ylyPrinterKey,RedisCode::SYSTEM_DB)) $this->__initPrinterListData(); $res = $this->redisCache->get($this->ylyPrinterKey, RedisCode::SYSTEM_DB); if (empty($res)) return []; return json_decode($res, true); } /** * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function getOtherPrinter(): array { if (!$this->redisCache->exists($this->jdPrinterKey,RedisCode::SYSTEM_DB)) $this->__initPrinterListData(); $res = $this->redisCache->get($this->jdPrinterKey, RedisCode::SYSTEM_DB); if (empty($res)) return []; return json_decode($res, true); } /** * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function delCache(): void { $this->redisCache->delete($this->ylyPrinterKey,RedisCode::SYSTEM_DB); $this->redisCache->delete($this->jdPrinterKey,RedisCode::SYSTEM_DB); } }