info('export ai pali word token'); Log::debug('export ai pali word token'); if (\App\Tools\Tools::isStop()) { return 0; } $exportDir = storage_path('app/tmp/export/offline'); if (!is_dir($exportDir)) { $res = mkdir($exportDir, 0755, true); if (!$res) { $this->error('mkdir fail path=' . $exportDir); return 1; } else { $this->info('make dir successful ' . $exportDir); } } $dict_id = DictApi::getSysDict('system_preference'); if (!$dict_id) { $this->error('没有找到 system_preference 字典'); return 1; } $filename = 'ai-pali-word-token-' . date("Y-m-d") . '.tsv'; $exportFile = $exportDir . '/' . $filename; $fp = fopen($exportFile, 'w'); if ($fp === false) { $this->error('无法创建文件'); return 1; } $start = time(); $total = UserDict::where('dict_id', $dict_id)->count(); $words = UserDict::where('dict_id', $dict_id) ->select([ 'word', 'factors', ])->cursor(); foreach ($words as $key => $word) { $output = array($word->word, $word->factors); fwrite($fp, implode("\t", $output) . "\n"); if ($key % 100 === 0) { $present = (int)($key * 100 / $total); $this->info("[{$present}%]-{$key}"); } } fclose($fp); $this->info((time() - $start) . ' seconds'); $this->call('export:zip', [ 'id' => 'ai-pali-word-token', 'filename' => $exportFile, 'title' => 'ai pali word token', 'format' => $this->option('format'), ]); return 0; } }