Browse Source

first commit

liuhairui 2 weeks ago
parent
commit
b685ca69cf
2 changed files with 34 additions and 26 deletions
  1. 31 23
      application/api/controller/Index.php
  2. 3 3
      public/assets/js/backend/newrecords.js

+ 31 - 23
application/api/controller/Index.php

@@ -258,6 +258,7 @@ class Index extends Api
                 'sys_rq'       => date('Y-m-d H:i:s'),
                 'gender'       => $item['gender'] ?? '',
                 'birthDate'    => $item['birthDate'] ?? '',
+                'category'    => $item['category'] ?? '',
                 'notes'        => $item['notes'] ?? '',
             ];
         }
@@ -296,42 +297,49 @@ class Index extends Api
         if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
             exit;
         }
-        
-        // 创建最终返回的数据数组
+
+        // 创建rfid映射,用于去重和优先级控制
+        $rfidMap = [];
         $list = [];
-        
-        // 查询new_records表的所有数据,保持原样
-        $newRecordsData = Db::name("new_records")
-            ->select();
-        
-        // 将new_records表的数据添加到结果数组
-        if (!empty($newRecordsData)) {
-            $list = array_merge($list, $newRecordsData);
-        }
-        
+
         // 查询records表的数据,按sys_rq倒序
         $recordsData = Db::name("records")
             ->order('sys_rq DESC')
             ->select();
-        
-        // 对records表数据按rfid去重,只保留每个rfid最新的一条记录
-        $rfidMap = [];
-        $uniqueRecords = [];
-        
+
+        // 先处理records表数据,记录rfid映射
         foreach ($recordsData as $record) {
             $rfid = trim($record['rfid']);
             // 如果这个rfid还没有处理过,则添加到结果中
             if (!isset($rfidMap[$rfid])) {
                 $rfidMap[$rfid] = true;
-                $uniqueRecords[] = $record;
+                $list[] = $record;
             }
         }
-        
-        // 将去重后的records表数据添加到结果数组
-        if (!empty($uniqueRecords)) {
-            $list = array_merge($list, $uniqueRecords);
+
+        // 查询new_records表的所有数据
+        $newRecordsData = Db::name("new_records")
+            ->select();
+
+        // 再处理new_records表数据,优先保留
+        foreach ($newRecordsData as $record) {
+            $rfid = trim($record['rfid']);
+
+            if (isset($rfidMap[$rfid])) {
+                // 如果rfid已存在,则替换list中对应的记录
+                foreach ($list as $key => $item) {
+                    if (trim($item['rfid']) === $rfid) {
+                        $list[$key] = $record;
+                        break;
+                    }
+                }
+            } else {
+                // 如果rfid不存在,则添加到list并记录rfid映射
+                $rfidMap[$rfid] = true;
+                $list[] = $record;
+            }
         }
-        
+
         return json([
             'code' => 0,
             'msg' => '数据获取成功',

+ 3 - 3
public/assets/js/backend/newrecords.js

@@ -31,12 +31,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'username', title: '用户名', operate: 'LIKE'},
                         {field: 'userId', title: '用户ID', operate: 'LIKE'},
                         {field: 'rfid', title: '电子耳标号', operate: 'LIKE'},
+                        {field: 'category', title: "品类", operate: 'LIKE'},
+                        {field: 'gender', title:"性别", operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'buildingName', title:'栋舍', operate: 'LIKE'},
                         {field: 'roomName', title:'房间号', operate: 'LIKE'},
                         {field: 'penNo', title:'栏位号', operate: 'LIKE'},
-                        {field: 'birthDate', title:"出生日期", operate: 'LIKE'},
-                        {field: 'category', title: "品类", operate: 'LIKE'},
-                        {field: 'gender', title:"性别", operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
+                        // {field: 'birthDate', title:"出生日期", operate: 'LIKE'},
                         {field: 'sys_rq', title: "创建日期", operate: 'LIKE'},
                         // {field: 'dayage', title: "日龄", operate: 'LIKE'},
                         // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}