原始rfid导入

This commit is contained in:
chenbo 2024-01-29 14:03:07 +08:00
parent fbababf4dc
commit 184aa00784
6 changed files with 165 additions and 80 deletions

View File

@ -14,6 +14,7 @@
<el-form-item> <el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button> <el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button> <el-button @click="resetParams">重置</el-button>
<el-button type="primary" @click="handleImport">导入</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
@ -35,7 +36,17 @@
<el-table :data="pager.lists" @selection-change="handleSelectionChange"> <el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
<el-table-column label="RFID" prop="rfid" show-overflow-tooltip /> <el-table-column label="RFID" prop="rfid" show-overflow-tooltip />
<el-table-column label="所属栏舍" prop="fence_house_id" show-overflow-tooltip /> <el-table-column label="原始RFID" prop="origin_rfid" />
<el-table-column label="所属栏舍" prop="fence_house_id" show-overflow-tooltip>
<template #default="{ row }">
<el-tag class="mr-2" v-if="row.fence_house_id != null" type="info"
>ID: {{ row.fence_house_id }}</el-tag
>
<el-tag class="mr-2" v-if="row.fenceHouse != null" type="info"
>名称: {{ row.fenceHouse.fence_house_name }}</el-tag
>
</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right"> <el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }"> <template #default="{ row }">
@ -70,6 +81,29 @@
@success="getLists" @success="getLists"
@close="showEdit = false" @close="showEdit = false"
/> />
<div>
<el-dialog v-model="showImport" @close="showImport = false" width="30%">
<el-upload
style="margin-left: 12px;"
ref="uploadImportRef"
class="upload-demo"
:action="uploadAction"
:headers="{ Token: userStore.token }"
:limit="1"
:on-exceed="handleExceed"
:auto-upload="false"
>
<template #trigger>
<el-button type="primary">选择文件</el-button>
</template>
<el-button class="ml-3" type="success" @click="submitUpload">
提交
</el-button>
</el-upload>
</el-dialog>
</div>
</div> </div>
</template> </template>
@ -80,11 +114,19 @@ import { apiAnimalRfidLists, apiAnimalRfidDelete } from '@/api/animal_rfid'
import { timeFormat } from '@/utils/util' import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback' import feedback from '@/utils/feedback'
import EditPopup from './edit.vue' import EditPopup from './edit.vue'
import { genFileId, ElMessage } from 'element-plus'
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus'
import {ref} from "vue";
import config from "@/config";
import useUserStore from "@/stores/modules/user";
const editRef = shallowRef<InstanceType<typeof EditPopup>>() const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const uploadImportRef = ref<UploadInstance>()
// //
const showEdit = ref(false) const showEdit = ref(false)
const showImport = ref(false)
const uploadAction = ref(`${config.baseUrl}${config.urlPrefix}/device.device/importRfid`)
const userStore = useUserStore()
// //
const queryParams = reactive({ const queryParams = reactive({
rfid: '' rfid: ''
@ -128,6 +170,22 @@ const handleDelete = async (id: number | any[]) => {
await apiAnimalRfidDelete({ id }) await apiAnimalRfidDelete({ id })
getLists() getLists()
} }
const handleImport = async () => {
showImport.value = true
await nextTick()
}
const handleExceed: UploadProps['onExceed'] = (files) => {
uploadImportRef.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadImportRef.value!.handleStart(file)
}
const submitUpload = () => {
uploadImportRef.value!.submit()
showImport.value=false
ElMessage.success('导入成功')
getLists()
}
getLists() getLists()
</script> </script>

View File

@ -20,7 +20,11 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\device\DeviceLists; use app\adminapi\lists\device\DeviceLists;
use app\adminapi\logic\device\DeviceLogic; use app\adminapi\logic\device\DeviceLogic;
use app\adminapi\validate\device\DeviceValidate; use app\adminapi\validate\device\DeviceValidate;
use app\common\service\ConfigService;
use app\common\service\storage\Driver as StorageDriver;
use PhpOffice\PhpSpreadsheet\IOFactory;
use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\HttpClient;
use think\facade\Db;
/** /**
@ -148,4 +152,22 @@ class DeviceController extends BaseAdminController
return $this->data($datas); return $this->data($datas);
} }
public function importRfid()
{
$reader = IOFactory::createReader('Xls');
// 打开文件 载入excel表格
$spreadsheet = $reader->load($_FILES['file']['tmp_name']);
$excelData = $spreadsheet->getActiveSheet()->toArray();
array_shift($excelData); // 去除表头
$insertData = [];
foreach ($excelData as $key =>$row) {
$insertData[$key]['origin_rfid'] = $row[0];
$insertData[$key]['rfid'] = $row[1];
}
Db::name('animal_rfid')->insertAll($insertData);
return $this->success('导入成功');
}
} }

View File

@ -39,6 +39,7 @@ class AnimalRfidLists extends BaseAdminDataLists implements ListsSearchInterface
{ {
return [ return [
'=' => ['rfid'], '=' => ['rfid'],
]; ];
} }
@ -55,7 +56,7 @@ class AnimalRfidLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array public function lists(): array
{ {
return AnimalRfid::where($this->searchWhere) return AnimalRfid::where($this->searchWhere)
->field(['id', 'rfid', 'fence_house_id']) ->with(['fenceHouse'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()

View File

@ -37,7 +37,7 @@ class AnimalRfid extends BaseModel
* @author likeadmin * @author likeadmin
* @date 2024/01/13 16:21 * @date 2024/01/13 16:21
*/ */
public function fenceHouseAttr() public function fenceHouse()
{ {
return $this->hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id'); return $this->hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id');
} }

View File

@ -42,7 +42,7 @@ abstract class Server
} }
// 校验上传文件后缀 // 校验上传文件后缀
$limit = array_merge(config('project.file_image'), config('project.file_video')); $limit = array_merge(config('project.file_image'), config('project.file_video'), config('project.file_file'));
if (!in_array(strtolower($this->file->extension()), $limit)) { if (!in_array(strtolower($this->file->extension()), $limit)) {
throw new Exception('不允许上传' . $this->file->extension() . '后缀文件'); throw new Exception('不允许上传' . $this->file->extension() . '后缀文件');
} }

View File

@ -74,6 +74,10 @@ return [
'wmv', 'avi', 'mpg', 'mpeg', '3gp', 'mov', 'mp4', 'flv', 'f4v', 'rmvb', 'mkv' 'wmv', 'avi', 'mpg', 'mpeg', '3gp', 'mov', 'mp4', 'flv', 'f4v', 'rmvb', 'mkv'
], ],
// 文件上传限制 (文件)
'file_file' => [
'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt','apk','ipa','wgt'
],
// 登录设置 // 登录设置
'login' => [ 'login' => [
// 登录方式1-账号密码登录2-手机短信验证码登录 // 登录方式1-账号密码登录2-手机短信验证码登录