ソースを参照

增加筛选选项的接口

LAPTOP-VT1IP978\suxio 2 週間 前
コミット
6c99e382b9

+ 8 - 0
README.md

@@ -1,5 +1,13 @@
 # 电子药检报告
 
+## 环境要求
+
+- PHP 7.4
+- Laravel 8.3
+- MySQL 5.7
+
+## 同步数据脚本
+
 ```bash
 php artisan sync:drug-report --source=querydrugreport --full --start-time="2025-01-01 00:00:00"
 ```

+ 33 - 2
app/Http/Controllers/DrugReportInfoController.php

@@ -19,7 +19,7 @@ class DrugReportInfoController extends Controller
     public function index(ListRequest $request, DrugReportInfoService $service)
     {
         try {
-            Log::channel('api')->info('查询医药报告信息', [
+            Log::channel('api')->info('/api/drug-report-info', [
                 'ip' => $request->ip(),
                 'user_agent' => $request->userAgent(),
                 'data' => $request->all()
@@ -34,7 +34,38 @@ class DrugReportInfoController extends Controller
 
             return $this->success(new DrugReportInfoListResource($list));
         } catch (\Exception $e) {
-            Log::channel('api')->error('查询医药报告信息失败', [
+            Log::channel('api')->error('/api/drug-report-info', [
+                'error' => $e->getMessage(),
+                'trace' => $e->getTraceAsString()
+            ]);
+
+            return $this->error($e->getCode(), $e->getMessage());
+        }
+    }
+
+    /**
+     * 查询医药报告选项
+     * @param ListRequest $request
+     * @param DrugReportInfoService $service
+     * @return JsonResponse
+     */
+    public function option(ListRequest $request, DrugReportInfoService $service)
+    {
+        try {
+            Log::channel('api')->info('/api/drug-report-info/option', [
+                'ip' => $request->ip(),
+                'user_agent' => $request->userAgent(),
+                'data' => $request->all()
+            ]);
+
+            $data = [
+                'produce_ent' => $service->getProduceEntIdOption(),
+                'from_ref_ent' => $service->getFromRefEntIdOption(),
+            ];
+
+            return $this->success($data);
+        } catch (\Exception $e) {
+            Log::channel('api')->error('/api/drug-report-info/option', [
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);

+ 26 - 0
app/Services/DrugReportInfoService.php

@@ -22,4 +22,30 @@ class DrugReportInfoService
 
         return $query->paginate($perPage);
     }
+
+    /**
+     * 获取生产企业选项
+     * @return array
+     */
+    public function getProduceEntIdOption(): array
+    {
+        return DrugReportInfo::query()
+            ->where('produce_ent_id', '!=', '')
+            ->pluck('produce_ent_name', 'produce_ent_id')
+            ->unique()
+            ->toArray();
+    }
+
+    /**
+     * 获取发货企业选项
+     * @return array
+     */
+    public function getFromRefEntIdOption(): array
+    {
+        return DrugReportInfo::query()
+            ->where('from_ref_ent_id', '!=', '')
+            ->pluck('from_ent_name', 'from_ref_ent_id')
+            ->unique()
+            ->toArray();
+    }
 }

+ 1 - 0
routes/api.php

@@ -28,4 +28,5 @@ Route::prefix('ali-health')->group(function () {
 
 Route::prefix('drug-report-info')->group(function () {
     Route::get('/', [DrugReportInfoController::class, 'index']);
+    Route::get('/option', [DrugReportInfoController::class, 'option']);
 });